Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 deletions powershell/cmdlets/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,60 @@ export function addDefaultInfo(targetProperty: Property, parameter: any) {

export function addInfoAttribute(targetProperty: Property, pType: TypeDeclaration, isRequired: boolean, isReadOnly: boolean, description: string, serializedName: string) {

let pt = <any>pType;
while (pt.elementType) {
switch (pt.elementType.schema.type) {
case JsonType.Object:
if (pt.elementType.schema.details.csharp.interfaceImplementation) {
pt = {
declaration: pt.elementType.schema.details.csharp.interfaceImplementation.declaration,
schema: pt.elementType.schema,
};
} else {
// arg! it's not done yet. Hope it's not polymorphic itself.
pt = {
declaration: `${pt.elementType.schema.details.csharp.namespace}.${pt.elementType.schema.details.csharp.interfaceName}`,
schema: pt.elementType.schema,
};
}
break;

case JsonType.Array:
pt = pt.elementType;
break;

default:
pt = pt.elementType;
break;
}
}
const ptypes = new Array<string>();
if (pt.schema && pt.schema && pt.schema.details.csharp.byReference) {
ptypes.push(`typeof(${pt.schema.details.csharp.namespace}.${pt.schema.details.csharp.interfaceName}_Reference)`);
// do we need polymorphic types for by-resource ? Don't think so.
} else {
ptypes.push(`typeof(${pt.declaration})`);
if (pt.schema && pt.schema.details.csharp.classImplementation && pt.schema.details.csharp.classImplementation.discriminators) {
ptypes.push(...[...pt.schema.details.csharp.classImplementation.discriminators.values()].map(each => `typeof(${each.modelInterface.fullName})`));
}
}

targetProperty.add(new Attribute(ClientRuntime.InfoAttribute, {
parameters: [
new LiteralExpression(`\nRequired = ${isRequired}`),
new LiteralExpression(`\nReadOnly = ${isReadOnly}`),
new LiteralExpression(`\nDescription = ${new StringExpression(description).value}`),
new LiteralExpression(`\nSerializedName = ${new StringExpression(serializedName).value}`),
new LiteralExpression(`\nPossibleTypes = new [] { ${ptypes.join(',').replace(/\?/g, '').replace(/undefined\./g, '')} }`),
]
}));


}


export function NewAddInfoAttribute(targetProperty: Property, pType: TypeDeclaration, isRequired: boolean, isReadOnly: boolean, description: string, serializedName: string) {

let pt = <any>pType;
while (pt.elementType) {
switch (pt.elementType.schema.type) {
Expand Down Expand Up @@ -2403,7 +2457,7 @@ export class NewCmdletClass extends Class {
} else {
cmdletParameter.add(new Attribute(ParameterAttribute, { parameters: [new LiteralExpression(`Mandatory = ${vParam.required ? 'true' : 'false'}`), new LiteralExpression(`HelpMessage = "${escapeString(desc || '.')}"`)] }));
cmdletParameter.add(new Attribute(CategoryAttribute, { parameters: [`${ParameterCategory}.Body`] }));
addInfoAttribute(cmdletParameter, propertyType, !!vParam.required, false, desc, (<NewVirtualProperty>vParam.origin).property.serializedName);
NewAddInfoAttribute(cmdletParameter, propertyType, !!vParam.required, false, desc, (<NewVirtualProperty>vParam.origin).property.serializedName);
NewAddCompleterInfo(cmdletParameter, vParam);
addDefaultInfo(cmdletParameter, vParam);
}
Expand Down Expand Up @@ -2522,7 +2576,7 @@ export class NewCmdletClass extends Class {
regularCmdletParameter.add(new Attribute(AllowEmptyCollectionAttribute));
}

addInfoAttribute(regularCmdletParameter, propertyType, vParam.required, false, vParam.description, vParam.origin.name);
NewAddInfoAttribute(regularCmdletParameter, propertyType, vParam.required, false, vParam.description, vParam.origin.name);
NewAddCompleterInfo(regularCmdletParameter, vParam);
addDefaultInfo(regularCmdletParameter, vParam);

Expand Down Expand Up @@ -2644,7 +2698,7 @@ export class NewCmdletClass extends Class {
shouldAddPassThru = shouldAddPassThru || values(operation.callGraph)
.selectMany(httpOperation => values(httpOperation.responses))
//.selectMany(responsesItem => responsesItem.value)
.any(value => value instanceof SchemaResponse);
.any(value => (<SchemaResponse>value).schema === undefined);
if (outputTypes.size === 0) {
outputTypes.add(`typeof(${dotnet.Bool})`);
}
Expand Down
4 changes: 2 additions & 2 deletions powershell/llcsharp/model/model-class-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@ export class NewJsonSerializableClass extends Class {

pushTempVar();
for (const prop of values(modelClass.ownedProperties)) {
if (prop.details.csharp.HeaderProperty === 'Header') {
if (prop.language.csharp.HeaderProperty === 'Header') {
continue;
}
const serializeStatement = (<EnhancedTypeDeclaration>prop.type).serializeToContainerMember(KnownMediaType.Json, prop.valuePrivate, container, prop.serializedName, mode);

if (prop.details.csharp.readOnly) {
if (prop.language.csharp.readOnly) {
serializeStatements.add(If(`${mode.use}.HasFlag(${ClientRuntime.SerializationMode.IncludeReadOnly})`, serializeStatement));
} else {
serializeStatements.add(serializeStatement);
Expand Down
Loading