diff --git a/powershell/llcsharp/model/model-class.ts b/powershell/llcsharp/model/model-class.ts index 6fbf72d031..c80abb95ba 100644 --- a/powershell/llcsharp/model/model-class.ts +++ b/powershell/llcsharp/model/model-class.ts @@ -552,10 +552,10 @@ export class NewModelClass extends Class implements NewEnhancedTypeDeclaration { public get schema() { return this.featureImplementation.schema; } /* @internal */ validateMethod?: Method; - /* @internal */ discriminators: Map = new Map(); - /* @internal */ parentModelClasses: Array = new Array(); - /* @internal */ get modelInterface(): ModelInterface { return this.schema.language.csharp?.interfaceImplementation; } - /* @internal */ get internalModelInterface(): ModelInterface { return this.schema.language.csharp?.internalInterfaceImplementation; } + /* @internal */ discriminators: Map = new Map(); + /* @internal */ parentModelClasses: Array = new Array(); + /* @internal */ get modelInterface(): NewModelInterface { return this.schema.language.csharp?.interfaceImplementation; } + /* @internal */ get internalModelInterface(): NewModelInterface { return this.schema.language.csharp?.internalInterfaceImplementation; } /* @internal */ state: NewState; /* @internal */ backingFields = new Array(); @@ -586,8 +586,7 @@ export class NewModelClass extends Class implements NewEnhancedTypeDeclaration { // must be a partial class this.partial = true; - //skip-for-time-being - //this.handleDiscriminator(); + this.handleDiscriminator(); // create an interface for this model class if (!this.schema.language.csharp.interfaceImplementation) { @@ -611,12 +610,12 @@ export class NewModelClass extends Class implements NewEnhancedTypeDeclaration { // skip-for-time-being // handle parent interface implementation - // if (!this.handleAllOf()) { - // // handle the AdditionalProperties if used - // if (this.schema.additionalProperties) { - // this.dictionaryImpl = new DictionaryImplementation(this).init(); - // } - // } + if (!this.handleAllOf()) { + // handle the AdditionalProperties if used + // if (this.schema.additionalProperties) { + // this.dictionaryImpl = new DictionaryImplementation(this).init(); + // } + } // create the properties for ths schema this.createProperties(); @@ -838,7 +837,7 @@ export class NewModelClass extends Class implements NewEnhancedTypeDeclaration { } } - private additionalPropertiesType(aSchema: Schema): TypeDeclaration | undefined { + private additionalPropertiesType(aSchema: NewSchema): TypeDeclaration | undefined { // skip-for-time-being // if (aSchema.additionalProperties) { @@ -859,76 +858,75 @@ export class NewModelClass extends Class implements NewEnhancedTypeDeclaration { return undefined; } - // skip-for-time-being - // private handleAllOf() { - // let hasAdditionalPropertiesInParent = false; - // // handle s - // // add an 'implements' for the interface for the allOf. - // for (const { key: eachSchemaIndex, value: eachSchemaValue } of items(this.schema.allOf)) { - // const aSchema = eachSchemaValue; - // const aState = this.state.path('allOf', eachSchemaIndex); - - // const td = this.state.project.modelsNamespace.resolveTypeDeclaration(aSchema, true, aState); - // const parentClass = (aSchema.details.csharp.classImplementation); - // const className = parentClass.fullName; - // const fieldName = camelCase(deconstruct(className.replace(/^.*\./, ''))); - - // // add the interface as a parent to our interface. - // const iface = aSchema.details.csharp.interfaceImplementation; - - // // add a field for the inherited values - // const backingField = this.addField(new Field(`__${fieldName}`, td, { initialValue: `new ${className}()`, access: Access.Private, description: `Backing field for Inherited model ` })); - // this.backingFields.push({ - // className, - // typeDeclaration: td, - // field: backingField - // }); - // this.validationStatements.add(td.validatePresence(this.validationEventListener, backingField)); - // this.validationStatements.add(td.validateValue(this.validationEventListener, backingField)); - - // this.internalModelInterface.interfaces.push(aSchema.details.csharp.internalInterfaceImplementation); - // this.modelInterface.interfaces.push(iface); - - // // - // const addlPropType = this.additionalPropertiesType(aSchema); - // if (addlPropType) { - // this.dictionaryImpl = new DictionaryImplementation(this).init(addlPropType, backingField); - // hasAdditionalPropertiesInParent = true; - // } - // } - // return hasAdditionalPropertiesInParent; - // } - - // private handleDiscriminator() { - // if (this.schema.discriminator) { - // // this has a discriminator property. - // // our children are expected to tell us who they are - // this.isPolymorphic = true; - // // we'll add a deserializer factory method a bit later.. - // } - - // if (this.schema.details.csharp.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.allOf)) { - // const parentSchema = eachAllOfValue; - // const aState = this.state.path('allOf', eachAllOfIndex); - - // // ensure the parent schema has it's class created first. - // this.state.project.modelsNamespace.resolveTypeDeclaration(parentSchema, true, aState); - - // const parentClass = parentSchema.details.csharp.classImplementation; - // if (parentClass.isPolymorphic) { - // // remember this class for later. - // this.parentModelClasses.push(parentClass); - - // // tell that parent who we are. - // parentClass.addDiscriminator(this.schema.details.csharp.discriminatorValue, this); - // } - // } - // } - // } + private handleAllOf() { + let hasAdditionalPropertiesInParent = false; + // handle s + // add an 'implements' for the interface for the allOf. + for (const { key: eachSchemaIndex, value: eachSchemaValue } of items(this.schema.parents?.immediate)) { + const aSchema = eachSchemaValue; + const aState = this.state.path('allOf', eachSchemaIndex); + + const td = this.state.project.modelsNamespace.NewResolveTypeDeclaration(aSchema, true, aState); + const parentClass = (aSchema.language.csharp?.classImplementation); + const className = parentClass.fullName; + const fieldName = camelCase(deconstruct(className.replace(/^.*\./, ''))); + + // add the interface as a parent to our interface. + const iface = aSchema.language.csharp?.interfaceImplementation; + + // add a field for the inherited values + const backingField = this.addField(new Field(`__${fieldName}`, td, { initialValue: `new ${className}()`, access: Access.Private, description: `Backing field for Inherited model ` })); + this.backingFields.push({ + className, + typeDeclaration: td, + field: backingField + }); + this.validationStatements.add(td.validatePresence(this.validationEventListener, backingField)); + this.validationStatements.add(td.validateValue(this.validationEventListener, backingField)); + + this.internalModelInterface.interfaces.push(aSchema.language.csharp?.internalInterfaceImplementation); + this.modelInterface.interfaces.push(iface); + + // + const addlPropType = this.additionalPropertiesType(aSchema); + if (addlPropType) { + // this.dictionaryImpl = new DictionaryImplementation(this).init(addlPropType, backingField); + // hasAdditionalPropertiesInParent = true; + } + } + return hasAdditionalPropertiesInParent; + } + + private handleDiscriminator() { + if (this.schema.discriminator) { + // this has a discriminator property. + // our children are expected to tell us who they are + this.isPolymorphic = true; + // we'll add a deserializer factory method a bit later.. + } + + if (this.schema.language.csharp?.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)) { + const parentSchema = eachAllOfValue; + const aState = this.state.path('allOf', eachAllOfIndex); + + // ensure the parent schema has it's class created first. + this.state.project.modelsNamespace.NewResolveTypeDeclaration(parentSchema, true, aState); + + const parentClass = parentSchema.language.csharp?.classImplementation; + if (parentClass.isPolymorphic) { + // remember this class for later. + this.parentModelClasses.push(parentClass); + + // tell that parent who we are. + parentClass.addDiscriminator(this.schema.language.csharp.discriminatorValue, this); + } + } + } + } private addHeaderDeserializer() { const avp = getAllVirtualProperties(this.schema.language.csharp?.virtualProperties); const headers = new Parameter('headers', System.Net.Http.Headers.HttpResponseHeaders); @@ -960,7 +958,7 @@ export class NewModelClass extends Class implements NewEnhancedTypeDeclaration { return this.featureImplementation.validatePresence(eventListener, property); } - public addDiscriminator(discriminatorValue: string, modelClass: ModelClass) { + public addDiscriminator(discriminatorValue: string, modelClass: NewModelClass) { this.discriminators.set(discriminatorValue, modelClass); // tell any polymorphic parents incase we're doing subclass of a subclass. diff --git a/powershell/llcsharp/schema/schema-resolver.ts b/powershell/llcsharp/schema/schema-resolver.ts index b33b5ae2d0..0885d402d7 100644 --- a/powershell/llcsharp/schema/schema-resolver.ts +++ b/powershell/llcsharp/schema/schema-resolver.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { codeModelSchema, ArraySchema, CodeModel, Schema as NewSchema, StringSchema, BooleanSchema, NumberSchema, ByteArraySchema, ObjectSchema, GroupSchema, isObjectSchema, SchemaType, GroupProperty, ParameterLocation, Operation, Parameter, VirtualParameter, getAllProperties, ImplementationLocation, OperationGroup, Request, SchemaContext, ConstantSchema, ChoiceSchema } from '@azure-tools/codemodel'; +import { codeModelSchema, ArraySchema, CodeModel, Schema as NewSchema, StringSchema, BooleanSchema, NumberSchema, ByteArraySchema, DateTimeSchema, ObjectSchema, GroupSchema, isObjectSchema, SchemaType, GroupProperty, ParameterLocation, Operation, Parameter, VirtualParameter, getAllProperties, ImplementationLocation, OperationGroup, Request, SchemaContext, ConstantSchema, ChoiceSchema } from '@azure-tools/codemodel'; import { ModelState, codemodel, IntegerFormat, NumberFormat, StringFormat, JsonType } from '@azure-tools/codemodel-v3'; import { Schema } from '../code-model'; @@ -186,6 +186,9 @@ export class NewSchemaDefinitionResolver { } + case SchemaType.DateTime: + return new NewDateTime(schema, required); + case SchemaType.Boolean: return new NewBoolean(schema, required); diff --git a/powershell/plugins/plugin-create-inline-properties.ts b/powershell/plugins/plugin-create-inline-properties.ts index 061b706cc9..84656151f9 100644 --- a/powershell/plugins/plugin-create-inline-properties.ts +++ b/powershell/plugins/plugin-create-inline-properties.ts @@ -238,7 +238,7 @@ function createVirtualProperties(schema: ObjectSchema, stack: Array, thr property: inlinedProperty.property, private: inlinedProperty.private, nameComponents: components, - nameOptions: getNameOptions(inlinedProperty.property.schema.details.default.name, components), + nameOptions: getNameOptions(inlinedProperty.property.schema.language.default.name, components), accessViaProperty: privateProperty, accessViaMember: inlinedProperty, accessViaSchema: schema, diff --git a/tests-upgrade/Configuration.json b/tests-upgrade/Configuration.json index fa0be4b88c..19d490b195 100644 --- a/tests-upgrade/Configuration.json +++ b/tests-upgrade/Configuration.json @@ -9,6 +9,7 @@ "basic-response-multioperation", "basic-spec-required", "basic-spec-root", + "component-definitions-combined", "component-definitions-local", "component-multiparam", "component-param", @@ -16,7 +17,8 @@ "component-param-localremote", "component-param-remote", "datamodels-datatypes-array", - "datamodels-datatypes-integer" + "datamodels-datatypes-integer", + "datamodels-datatypes-string" ], "BlackList": [ "basic-get-querystr",