in powershell/plugins/sdk-tweak-model.ts [87:140]
function tweakSchema(model: SdkModel) {
for (const obj of values(model.schemas.objects)) {
const optionalParameters = Array<string>();
const requiredParameters = Array<string>();
const optionalParametersWithoutReadOnly = Array<string>();
const requiredParametersWithoutReadOnly = Array<string>();
for (const property of values(obj.properties)) {
property.language.csharp = <any>{
name: property.language.default.name.substring(0, 1).toUpperCase() + property.language.default.name.substring(1),
formattedPropertySummary: (property.readOnly ? 'Gets ' : 'Gets or sets ') + property.language.default.description.substring(0, 1).toLowerCase() + property.language.default.description.substring(1)
};
}
const publicProperties = obj.extensions && obj.extensions['x-ms-azure-resource'] ? getAllPublicVirtualPropertiesForSdkWithoutInherited(obj.language.default.virtualProperties) : getAllPublicVirtualPropertiesForSdk(obj.language.default.virtualProperties);
for (const virtualProperty of publicProperties) {
if (virtualProperty.name.toLowerCase() === obj.language.default.name.toLowerCase()) {
// If the name is same as class name, will add 'Property' suffix
virtualProperty.name = virtualProperty.name + 'Property';
}
if (virtualProperty.required && (virtualProperty.property.schema.type === SchemaType.SealedChoice && (<SealedChoiceSchema>virtualProperty.property.schema).choices.length === 1)
|| (virtualProperty.property.schema.type === SchemaType.Choice && (<ChoiceSchema>virtualProperty.property.schema).choices.length === 1)) {
// For choice or seal choice with only one value and required, will not be handled as constant
continue;
}
let type = virtualProperty.property.schema.language.csharp?.fullname || '';
type = (valueType(virtualProperty.property.schema.type) || (virtualProperty.property.schema.type === SchemaType.SealedChoice && ((<SealedChoiceSchema>virtualProperty.property.schema).choiceType.type !== SchemaType.String || (virtualProperty.property.schema.extensions && !virtualProperty.property.schema.extensions['x-ms-model-as-string'])))) && !virtualProperty.required && virtualProperty.property.nullable != false ? `${type}?` : type;
const CamelName = camelCase(virtualProperty.name);
virtualProperty.required ? requiredParameters.push(`${type} ${CamelName}`) : optionalParameters.push(`${type} ${CamelName} = default(${type})`);
if (!virtualProperty.readOnly) {
virtualProperty.required ? requiredParametersWithoutReadOnly.push(`${type} ${CamelName}`) : optionalParametersWithoutReadOnly.push(`${type} ${CamelName} = default(${type})`);
}
}
if (obj.parents && (obj.parents.immediate.length === 1 && !(obj.extensions && obj.extensions['x-ms-azure-resource']))) {
// If there is only one direct parent parameter and extension x-ms-azure-resource is not set, will implement it as base class
let baseConstructorParametersCall = Array<string>();
const baseRequiredParameters = Array<string>();
const baseOptionalParameters = Array<string>();
const combinedProperties = getAllPublicVirtualPropertiesForSdk(obj.parents.immediate[0].language.default.virtualProperties);
for (const virtualProperty of values(combinedProperties)) {
if (virtualProperty.required) {
baseRequiredParameters.push(virtualProperty.name);
} else {
baseOptionalParameters.push(virtualProperty.name);
}
}
baseConstructorParametersCall = [...baseRequiredParameters, ...baseOptionalParameters].map((p) => camelCase(p) || '');
if (baseConstructorParametersCall.length > 0) {
obj.language.default.baseConstructorCall = `base(${baseConstructorParametersCall.join(', ')})`;
}
}
obj.language.default.constructorParametersDeclaration = [...requiredParameters, ...optionalParameters].join(', ');
obj.language.default.constructorParametersDeclarationWithoutReadOnly = [...requiredParametersWithoutReadOnly, ...optionalParametersWithoutReadOnly].join(', ');
}
}