diff --git a/src/transforms/mapperTransforms.ts b/src/transforms/mapperTransforms.ts index 62183fc1b281..11f56dc5ace4 100644 --- a/src/transforms/mapperTransforms.ts +++ b/src/transforms/mapperTransforms.ts @@ -32,7 +32,7 @@ export function transformMapper(obj: ObjectSchema): CompositeMapper { serializedName, required, isConstant, - defaultValue, + ...(defaultValue && { defaultValue }), type: getMapperType(type) }); }); diff --git a/src/transforms/operationTransforms.ts b/src/transforms/operationTransforms.ts index a89f593f6f5f..7f3db47e0a05 100644 --- a/src/transforms/operationTransforms.ts +++ b/src/transforms/operationTransforms.ts @@ -115,6 +115,7 @@ export function getSpecType(responseSchema: Schema, expand = false): SpecType { typeName = "String"; break; case SchemaType.Choice: + case SchemaType.SealedChoice: const choiceSchema = responseSchema as ChoiceSchema; typeName = "Enum"; allowedValues = choiceSchema.choices.map(choice => choice.value); diff --git a/src/transforms/transforms.ts b/src/transforms/transforms.ts index d008003a6575..653989e1da4b 100644 --- a/src/transforms/transforms.ts +++ b/src/transforms/transforms.ts @@ -9,7 +9,8 @@ import { CodeModel, ObjectSchema, Property, - ChoiceSchema + ChoiceSchema, + SealedChoiceSchema } from "@azure-tools/codemodel"; import { normalizeName, @@ -42,7 +43,9 @@ export function transformProperty(property: Property): PropertyDetails { }; } -export function transformChoice(choice: ChoiceSchema): UnionDetails { +export function transformChoice( + choice: ChoiceSchema | SealedChoiceSchema +): UnionDetails { const metadata = getLanguageMetadata(choice.language); let name = guardReservedNames(metadata.name); @@ -79,7 +82,10 @@ export function transformCodeModel(codeModel: CodeModel): ClientDetails { sourceFileName: normalizeName(className, NameType.File), models: (codeModel.schemas.objects || []).map(transformObject), mappers: (codeModel.schemas.objects || []).map(transformMapper), - unions: (codeModel.schemas.choices || []).map(transformChoice), + unions: [ + ...(codeModel.schemas.choices || []), + ...(codeModel.schemas.sealedChoices || []) + ].map(transformChoice), operationGroups: codeModel.operationGroups.map(transformOperationGroup) }; } diff --git a/src/utils/schemaHelpers.ts b/src/utils/schemaHelpers.ts index 08dfe1972676..309a4d5f3528 100644 --- a/src/utils/schemaHelpers.ts +++ b/src/utils/schemaHelpers.ts @@ -42,6 +42,6 @@ export function getTypeForSchema(schema: Schema): PropertyTypeDetails { return { typeName, isConstant: schema.type === SchemaType.Constant, - defaultValue + ...(defaultValue && { defaultValue }) }; } diff --git a/test/unit/utils/schemaHelpers.spec.ts b/test/unit/utils/schemaHelpers.spec.ts index 41b6cf211fdf..d5cb764269c7 100644 --- a/test/unit/utils/schemaHelpers.spec.ts +++ b/test/unit/utils/schemaHelpers.spec.ts @@ -17,8 +17,7 @@ describe("SchemaHelpers", () => { assert.deepEqual(typeDetails, { typeName: "string", - isConstant: false, - defaultValue: undefined + isConstant: false }); }); @@ -34,8 +33,7 @@ describe("SchemaHelpers", () => { assert.deepEqual(typeDetails, { typeName: "number", - isConstant: false, - defaultValue: undefined + isConstant: false }); }); @@ -51,8 +49,7 @@ describe("SchemaHelpers", () => { assert.deepEqual(typeDetails, { typeName: "number", - isConstant: false, - defaultValue: undefined + isConstant: false }); });