From dc5e590940f83d267afc350fdd399eea884deaa2 Mon Sep 17 00:00:00 2001 From: xichen Date: Tue, 25 Aug 2020 11:20:50 +0800 Subject: [PATCH] Fix enum boolean response which has only one value --- powershell/cmdlets/class.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/powershell/cmdlets/class.ts b/powershell/cmdlets/class.ts index 6e4b01d967..13091709d0 100644 --- a/powershell/cmdlets/class.ts +++ b/powershell/cmdlets/class.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Schema as NewSchema, SchemaType, ArraySchema, SchemaResponse, HttpParameter, ObjectSchema, DictionarySchema } from '@azure-tools/codemodel'; +import { Schema as NewSchema, SchemaType, ArraySchema, SchemaResponse, HttpParameter, ObjectSchema, DictionarySchema, ChoiceSchema, SealedChoiceSchema } from '@azure-tools/codemodel'; import { command, getAllProperties, JsonType, http, getAllPublicVirtualProperties, getVirtualPropertyFromPropertyName, ParameterLocation, getAllVirtualProperties, VirtualParameter, VirtualProperty } from '@azure-tools/codemodel-v3'; import { CommandOperation, VirtualParameter as NewVirtualParameter } from '../utils/command-operation'; import { getAllProperties as NewGetAllProperties, getAllPublicVirtualProperties as NewGetAllPublicVirtualProperties, getVirtualPropertyFromPropertyName as NewGetVirtualPropertyFromPropertyName, VirtualProperty as NewVirtualProperty } from '../utils/schema'; @@ -2665,7 +2665,9 @@ export class NewCmdletClass extends Class { const resultSchema = length(props) !== 1 ? schema : props[0].schema; // make sure return type for boolean stays boolean! - if (resultSchema.type === SchemaType.Boolean) { + if (resultSchema.type === SchemaType.Boolean || + (resultSchema.type === SchemaType.Choice && (resultSchema).choiceType.type === SchemaType.Boolean && (resultSchema).choices.length === 1) || + (resultSchema.type === SchemaType.SealedChoice && (resultSchema).choiceType.type === SchemaType.Boolean && (resultSchema).choices.length === 1)) { outputTypes.add(`typeof(${dotnet.Bool})`); } else { const typeDeclaration = this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(resultSchema, true, this.state);