From 078f32bb66e4fcd79b25ac68255f0d2c84f00c50 Mon Sep 17 00:00:00 2001 From: xichen Date: Mon, 24 Aug 2020 12:04:35 +0800 Subject: [PATCH] Fix choice issue (#675) Co-authored-by: xichen --- powershell/internal/project.ts | 6 ++++-- powershell/llcsharp/schema/schema-resolver.ts | 6 +----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/powershell/internal/project.ts b/powershell/internal/project.ts index 7724490d74a..1d0feb10bb0 100644 --- a/powershell/internal/project.ts +++ b/powershell/internal/project.ts @@ -17,7 +17,7 @@ import { codemodel, PropertyDetails, exportedModels as T, ModelState, JsonType, import { DeepPartial } from '@azure-tools/codegen'; import { PwshModel } from '../utils/PwshModel'; import { NewModelState } from '../utils/model-state'; -import { BooleanSchema, ConstantSchema, Schema as NewSchema, SchemaType } from '@azure-tools/codemodel'; +import { BooleanSchema, ChoiceSchema, ConstantSchema, Schema as NewSchema, SchemaType } from '@azure-tools/codemodel'; export type Schema = T.SchemaT, LanguageDetails>; @@ -72,7 +72,9 @@ export class NewPSSchemaResolver extends NewSchemaDefinitionResolver { try { if (!this.inResolve) { this.inResolve = true; - if (schema && (schema.type === SchemaType.Boolean || (schema.type === SchemaType.Constant && (schema).valueType.type === SchemaType.Boolean))) { + if (schema && (schema.type === SchemaType.Boolean + || (schema.type === SchemaType.Constant && (schema).valueType.type === SchemaType.Boolean) + || (schema.type === SchemaType.Choice && (schema).choiceType.type === SchemaType.Boolean))) { return new NewPSSwitch(schema, required); } } diff --git a/powershell/llcsharp/schema/schema-resolver.ts b/powershell/llcsharp/schema/schema-resolver.ts index 40e25040299..fe51afa73ef 100644 --- a/powershell/llcsharp/schema/schema-resolver.ts +++ b/powershell/llcsharp/schema/schema-resolver.ts @@ -238,11 +238,7 @@ export class NewSchemaDefinitionResolver { return this.resolveTypeDeclaration((schema).valueType, required, state); case SchemaType.Choice: { - const choiceSchema = schema as ChoiceSchema; - if ((choiceSchema.choiceType).type === SchemaType.DateTime && (choiceSchema.choiceType).format === StringFormat.DateTimeRfc1123) { - return new NewDateTime1123(schema as DateTimeSchema, required); - } - return new NewString(schema, required); + return this.resolveTypeDeclaration((schema).choiceType, required, state); } case SchemaType.SealedChoice: if (schema.language.default.skip === true) {