nameOptions: getNameOptions()

in powershell/plugins/plugin-create-inline-properties.ts [274:366]


          nameOptions: getNameOptions(inlinedProperty.property.schema.language.default.name, components),
          accessViaProperty: privateProperty,
          accessViaMember: inlinedProperty,
          accessViaSchema: schema,
          originalContainingSchema: schema,
          description: inlinedProperty.description,
          alias: [],
          create: create,
          update: update,
          read: read,
          readOnly: readonly,
          required: inlinedProperty.required && privateProperty.required
        });
      }
    } else {
      // otherwise, we're not below the threshold, and we should treat this as a non-inlined property
      nonObjectProperties.push(property);
    }
  }

  for (const property of nonObjectProperties) {
    const name = getPascalIdentifier(<string>property.language.default.name);
    // this is not something that has properties,
    // so we don't need to do any inlining
    // however, we can add it to our list of virtual properties
    // so that our consumers can get it.
    const mutability = getMutability(property);
    const combinedDescription = getCombinedDescription(property.language.default.description, property.schema?.externalDocs?.url);
    property.language.default.description = combinedDescription;

    virtualProperties.owned.push({
      name,
      property,
      nameComponents: [name],
      nameOptions: [name],
      description: property.summary || '',
      originalContainingSchema: schema,
      alias: [],
      create: mutability.create && !property.readOnly,
      update: mutability.update && !property.readOnly,
      read: mutability.read,
      readOnly: property.readOnly || (mutability.read && !mutability.create && !mutability.update),
      required: property.required || property.language.default.required
    });
  }

  // resolve name collisions.
  const allProps = [...virtualProperties.owned, ...virtualProperties.inherited, ...virtualProperties.inlined];
  const inlined = new Map<string, number>();

  for (const each of allProps) {
    // track number of instances of a given name.
    inlined.set(each.name, (inlined.get(each.name) || 0) + 1);
  }

  const usedNames = new Set(inlined.keys());
  for (const each of virtualProperties.inlined.sort((a, b) => length(a.nameOptions) - length(b.nameOptions))) {
    const ct = inlined.get(each.name);
    if (ct && ct > 1) {
      // console.error(`Fixing collision on name ${each.name} #${ct} `);
      each.name = selectName(each.nameOptions, usedNames);
    }
  }
  schema.language.default.inline = 'yes';
  return true;
}

function createVirtualParameters(operation: CommandOperation) {
  // dolauli expand body parameter
  // for virtual parameters, there are two keys, operation and body
  const virtualParameters = {
    operation: new Array<VirtualParameter>(),
    body: new Array<VirtualParameter>()
  };

  const dropBodyParameter = !!operation.details.default.dropBodyParameter;
  // loop thru the parameters of the command operation, and if there is a body parameter, expand it if necessary.
  for (const parameter of values(operation.parameters)) {
    if (parameter.details.default.constantValue) {
      // this parameter has a constant value -- SKIP IT
      continue;
    }
    // dolauli fromhost and apiversion are not exposed, this if block looks useless
    if (parameter.details.default.fromHost || parameter.details.default.apiversion) {
      // handled in the generator right now. Not exposed to the user directly.
      continue;
    }

    if (dropBodyParameter && parameter.details.default.isBodyParameter) {
      // the client will make a hidden body parameter for this, and we're expected to fill it.
      const vps = parameter.schema.language.default.virtualProperties;
      if (vps) {
        for (const virtualProperty of [...vps.inherited, ...vps.owned, ...vps.inlined]) {