Skip to content

Commit 2b337ef

Browse files
shawncxmsxichen
andauthored
Fix enum boolean response which has only one value (#676)
Co-authored-by: xichen <[email protected]>
1 parent 078f32b commit 2b337ef

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

powershell/cmdlets/class.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Schema as NewSchema, SchemaType, ArraySchema, SchemaResponse, HttpParameter, ObjectSchema, DictionarySchema } from '@azure-tools/codemodel';
6+
import { Schema as NewSchema, SchemaType, ArraySchema, SchemaResponse, HttpParameter, ObjectSchema, DictionarySchema, ChoiceSchema, SealedChoiceSchema } from '@azure-tools/codemodel';
77
import { command, getAllProperties, JsonType, http, getAllPublicVirtualProperties, getVirtualPropertyFromPropertyName, ParameterLocation, getAllVirtualProperties, VirtualParameter, VirtualProperty } from '@azure-tools/codemodel-v3';
88
import { CommandOperation, VirtualParameter as NewVirtualParameter } from '../utils/command-operation';
99
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 {
26652665
const resultSchema = length(props) !== 1 ? <NewSchema>schema : <NewSchema>props[0].schema;
26662666

26672667
// make sure return type for boolean stays boolean!
2668-
if (resultSchema.type === SchemaType.Boolean) {
2668+
if (resultSchema.type === SchemaType.Boolean ||
2669+
(resultSchema.type === SchemaType.Choice && (<any>resultSchema).choiceType.type === SchemaType.Boolean && (<ChoiceSchema>resultSchema).choices.length === 1) ||
2670+
(resultSchema.type === SchemaType.SealedChoice && (<any>resultSchema).choiceType.type === SchemaType.Boolean && (<SealedChoiceSchema>resultSchema).choices.length === 1)) {
26692671
outputTypes.add(`typeof(${dotnet.Bool})`);
26702672
} else {
26712673
const typeDeclaration = this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(resultSchema, true, this.state);

0 commit comments

Comments
 (0)