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
19 changes: 9 additions & 10 deletions powershell/llcsharp/model/model-class-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,15 @@ export class NewJsonSerializableClass extends Class {
yield If(Not(json.check), Return(dotnet.Null));
yield '// Polymorphic type -- select the appropriate constructor using the discriminator';
/** go thru the list of polymorphic values for the discriminator, and call the target class's constructor for that */
// skip-for-time-being
// if ($this.schema.discriminator) {
// yield Switch(toExpression(`json.StringProperty("${$this.schema.discriminator.propertyName}")`), function* () {
// for (const { key, value } of items(d)) {
// yield TerminalCase(`"${key}"`, function* () {
// yield Return(value.new(json));
// });
// }
// });
// }
if ($this.schema.discriminator) {
yield Switch(toExpression(`json.StringProperty("${$this.schema.discriminator.property.serializedName}")`), function* () {
for (const { key, value } of items(d)) {
yield TerminalCase(`"${key}"`, function* () {
yield Return(value.new(json));
});
}
});
}
yield Return($this.new(json, toExpression($excludes.substring(1))));
} else {
// just tell it to create the instance (providing that it's a JSonObject)
Expand Down
6 changes: 3 additions & 3 deletions powershell/llcsharp/model/model-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,11 +905,11 @@ export class NewModelClass extends Class implements NewEnhancedTypeDeclaration {
// we'll add a deserializer factory method a bit later..
}

if (this.schema.language.csharp?.discriminatorValue) {
if (this.schema.discriminatorValue) {
// we have a discriminator value, and we should tell our parent who we are so that they can build a proper deserializer method.
// um. just how do we *really* know which allOf is polymorphic?
// that's really sad.
for (const { key: eachAllOfIndex, value: eachAllOfValue } of items(this.schema.parents?.immediate)) {
for (const { key: eachAllOfIndex, value: eachAllOfValue } of items(this.schema.parents?.all)) {
const parentSchema = eachAllOfValue;
const aState = this.state.path('allOf', eachAllOfIndex);

Expand All @@ -922,7 +922,7 @@ export class NewModelClass extends Class implements NewEnhancedTypeDeclaration {
this.parentModelClasses.push(parentClass);

// tell that parent who we are.
parentClass.addDiscriminator(this.schema.language.csharp.discriminatorValue, this);
parentClass.addDiscriminator(this.schema.discriminatorValue, this);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions powershell/llcsharp/schema/schema-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class NewSchemaDefinitionResolver {
}
return this.add(schema, new NewObjectImplementation(<ObjectSchema>schema));
}
case SchemaType.SealedChoice:
case SchemaType.Choice:
case SchemaType.String: {
return new NewString(<StringSchema>schema, required);

Expand Down Expand Up @@ -226,7 +226,7 @@ export class NewSchemaDefinitionResolver {
state.error(`Unsupported constant type. Schema '${schema.language.csharp?.name}' is declared with invalid type '${schema.type}'`, message.UnknownJsonType);
throw new Error('Unknown Model. Fatal.');
}
case SchemaType.Choice:
case SchemaType.SealedChoice:
return new NewEnumImplementation(schema, required);
case undefined:
if (schema.extensions && schema.extensions['x-ms-enum']) {
Expand Down
6 changes: 3 additions & 3 deletions powershell/plugins/plugin-create-inline-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function createVirtualProperties(schema: ObjectSchema, stack: Array<string>, thr
originalContainingSchema: virtualProperty.originalContainingSchema,
description: virtualProperty.description,
alias: [],
required: virtualProperty.required, //|| !!values(schema.required).first(each => !!each && !!each.toLowerCase && each.toLowerCase() === virtualProperty.property.details.default.name.toLowerCase()),
required: virtualProperty.required || !!values(<Array<any>>virtualProperty.originalContainingSchema.properties).first(each => !!each && !!each.required && !!each.serializedName && each.serializedName.toLowerCase() === virtualProperty.property.language.default.name.toLowerCase()),
sharedWith: virtualProperty.sharedWith,
};
// add it to the list of virtual properties that share this property.
Expand Down Expand Up @@ -190,7 +190,7 @@ function createVirtualProperties(schema: ObjectSchema, stack: Array<string>, thr
description: property.summary || '',
originalContainingSchema: schema,
alias: [],
required: property.language.default.required,
required: !!property.required,
};
virtualProperties.owned.push(privateProperty);

Expand Down Expand Up @@ -268,7 +268,7 @@ function createVirtualProperties(schema: ObjectSchema, stack: Array<string>, thr
description: property.summary || '',
originalContainingSchema: schema,
alias: [],
required: property.language.default.required
required: !!property.required
});
}

Expand Down
6 changes: 2 additions & 4 deletions powershell/utils/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,9 @@ export interface SchemaDetails extends ImplementationDetails {
// }
// }

export function getPolymorphicBases(schema: Schema): Array<Schema> {
export function getPolymorphicBases(schema: ObjectSchema): Array<Schema> {
// are any of my parents polymorphic directly, or any of their parents?
// skip-for-time-being
// return [...values(schema).where(parent => parent.discriminator ? true : false), ...values(schema.allOf).selectMany(getPolymorphicBases)];
return [];
return [...values(schema.parents?.all).where(parent => (<ObjectSchema>parent).discriminator ? true : false)];
}

export function getAllProperties(schema: Schema): Array<Property> {
Expand Down
1 change: 1 addition & 0 deletions tests-upgrade/Configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"basic-response-multioperation",
"basic-spec-required",
"basic-spec-root",
"basic-polymorphism",
"component-definitions-combined",
"component-definitions-local",
"component-multiparam",
Expand Down
10 changes: 10 additions & 0 deletions tests-upgrade/basic-polymorphism/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### AutoRest Configuration
> see https://aka.ms/autorest

``` yaml
require:
- $(this-folder)/../readme.azure.noprofile.md
input-file:
- $(this-folder)/swagger.json

```
Loading