in powershell/plugins/sdk-create-inline-properties.ts [127:201]
name: getEscapedReservedName(virtualProperty.name, 'Property'),
property: virtualProperty.property,
private: virtualProperty.private,
nameComponents: virtualProperty.nameComponents,
nameOptions: virtualProperty.nameOptions,
accessViaProperty: virtualProperty,
accessViaMember: virtualProperty,
accessViaSchema: parentSchema,
originalContainingSchema: virtualProperty.originalContainingSchema,
description: virtualProperty.description,
alias: [],
create: virtualProperty.create,
update: virtualProperty.update,
read: virtualProperty.read,
readOnly: virtualProperty.readOnly,
required: virtualProperty.required,
sharedWith: virtualProperty.sharedWith,
serializedName: virtualProperty.serializedName
};
// add it to the list of virtual properties that share this property.
virtualProperty.sharedWith.push(inheritedProperty);
// add it to this class.
virtualProperties.inherited.push(inheritedProperty);
}
}
// dolauli figure out object properties and non object properties in this class
const [objectProperties, nonObjectProperties] = values(schema.properties).bifurcate(each =>
!schema.language.default['skip-inline'] && // if this schema is marked skip-inline, none can be inlined, treat them all as straight properties.
!each.schema.language.default['skip-inline'] && // if the property schema is marked skip-inline, then it should not be processed either.
each.extensions && each.extensions['x-ms-client-flatten'] && // only flatten when x-ms-client-flatten is set
each.schema.type === SchemaType.Object && // is it an object
getAllProperties(each.schema).length > 0 // does it have properties (or inherit properties)
);
// run thru the properties in this class.
// dolauli handle properties in this class
for (const property of objectProperties) {
if (isReserved(property.language.default.name)) {
property.language.default.name = camelCase(getEscapedReservedName(property.language.default.name, 'Property'));
}
const mutability = getMutability(property);
const propertyName = property.language.default.name;
// for each object member, make sure that it's inlined it's children that it can.
createVirtualProperties(<ObjectSchema>property.schema, [...stack, `${schema.language.default.name}`], conflicts);
// this happens if there is a circular reference.
// this means that this class should not attempt any inlining of that property at all .
// dolauli pay attention to the condition check
const isDict = property.schema.type === SchemaType.Dictionary || (<ObjectSchema>property.schema).parents?.immediate?.find((s) => s.type === SchemaType.Dictionary);
const canInline =
(!property.schema.language.default['skip-inline']) &&
(!<ObjectSchema>property.schema.language.default.byReference) &&
(!isDict) &&
property.extensions &&
property.extensions['x-ms-client-flatten'] &&
(<ObjectSchema>property.schema).language.default.inline === 'yes';
// the target has properties that we can inline
const virtualChildProperties = property.schema.language.default.virtualProperties || {
owned: [],
inherited: [],
inlined: [],
};
const allNotRequired = values(getAllPublicVirtualProperties()).all(each => !each.property.language.default.required);
if (canInline && (property.language.default.required || allNotRequired)) {
// if the child property is low enough (or it's 'properties'), let's create virtual properties for each one.
// create a private property for the inlined ones to use.
const privateProperty = {