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
166 changes: 82 additions & 84 deletions powershell/llcsharp/model/model-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,10 @@ export class NewModelClass extends Class implements NewEnhancedTypeDeclaration {
public get schema() { return this.featureImplementation.schema; }

/* @internal */ validateMethod?: Method;
/* @internal */ discriminators: Map<string, ModelClass> = new Map<string, ModelClass>();
/* @internal */ parentModelClasses: Array<ModelClass> = new Array<ModelClass>();
/* @internal */ get modelInterface(): ModelInterface { return <ModelInterface>this.schema.language.csharp?.interfaceImplementation; }
/* @internal */ get internalModelInterface(): ModelInterface { return <ModelInterface>this.schema.language.csharp?.internalInterfaceImplementation; }
/* @internal */ discriminators: Map<string, NewModelClass> = new Map<string, NewModelClass>();
/* @internal */ parentModelClasses: Array<NewModelClass> = new Array<NewModelClass>();
/* @internal */ get modelInterface(): NewModelInterface { return <NewModelInterface>this.schema.language.csharp?.interfaceImplementation; }
/* @internal */ get internalModelInterface(): NewModelInterface { return <NewModelInterface>this.schema.language.csharp?.internalInterfaceImplementation; }

/* @internal */ state: NewState;
/* @internal */ backingFields = new Array<BackingField>();
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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) {

Expand All @@ -859,76 +858,75 @@ export class NewModelClass extends Class implements NewEnhancedTypeDeclaration {
return undefined;
}

// skip-for-time-being
// private handleAllOf() {
// let hasAdditionalPropertiesInParent = false;
// // handle <allOf>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 = (<ModelClass>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 = <ModelInterface>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 <see cref= "${td.declaration}" /> ` }));
// 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(<ModelInterface>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 = <ModelClass>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 <allOf>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 = (<ModelClass>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 = <ModelInterface>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 <see cref= "${td.declaration}" /> ` }));
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(<ModelInterface>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 = <NewModelClass>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);
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion powershell/llcsharp/schema/schema-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -186,6 +186,9 @@ export class NewSchemaDefinitionResolver {

}

case SchemaType.DateTime:
return new NewDateTime(<DateTimeSchema>schema, required);

case SchemaType.Boolean:
return new NewBoolean(<BooleanSchema>schema, required);

Expand Down
2 changes: 1 addition & 1 deletion powershell/plugins/plugin-create-inline-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function createVirtualProperties(schema: ObjectSchema, stack: Array<string>, 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,
Expand Down
4 changes: 3 additions & 1 deletion tests-upgrade/Configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
"basic-response-multioperation",
"basic-spec-required",
"basic-spec-root",
"component-definitions-combined",
"component-definitions-local",
"component-multiparam",
"component-param",
"component-param-inbody",
"component-param-localremote",
"component-param-remote",
"datamodels-datatypes-array",
"datamodels-datatypes-integer"
"datamodels-datatypes-integer",
"datamodels-datatypes-string"
],
"BlackList": [
"basic-get-querystr",
Expand Down