From a3aaf4e3005b4eed4642a118130c2d18d0f728c0 Mon Sep 17 00:00:00 2001 From: Jose Manuel Heredia Hidalgo Date: Tue, 10 Dec 2019 14:17:29 -0800 Subject: [PATCH 1/2] Update version --- README.md | 2 +- package.json | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 41ec139d4414..ef46825dbb77 100755 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ More information about these can be found [here](https://github.com/Azure/autore ```yaml use-extension: - "@autorest/modelerfour": "4.0.52" + "@autorest/modelerfour": "4.2.75" pipeline: typescript: # <- name of plugin diff --git a/package.json b/package.json index 6a118a05cafa..f35ada4e6985 100755 --- a/package.json +++ b/package.json @@ -11,11 +11,11 @@ "start-test-server": "ts-node test/utils/start-server.ts", "stop-test-server": "stop-autorest-testserver", "debug": "node --inspect-brk ./dist/src/main.js", - "generate-bodystring": "npm run build && autorest-beta --typescript --output-folder=./generated/bodyString --use=. --title=BodyStringClient --input-file=node_modules/@autorest/test-server/__files/swagger/body-string.json --package-name=bodyString --package-version=1.0.0-preview1", - "generate-bodycomplex": "npm run build && autorest-beta --typescript --output-folder=./generated/bodyComplex --use=. --title=BodyComplexClient --input-file=node_modules/@autorest/test-server/__files/swagger/body-complex.json --package-name=bodyString --package-version=1.0.0-preview1" + "generate-bodystring": "npm run build && autorest-beta --version:3.0.6168 --use:@autorest/modelerfour@4.2.75 --typescript --output-folder=./generated/bodyString --use=. --title=BodyStringClient --input-file=node_modules/@microsoft.azure/autorest.testserver/swagger/body-string.json --package-name=bodyString --package-version=1.0.0-preview1", + "generate-bodycomplex": "npm run build && autorest-beta --version:3.0.6168 --use:@autorest/modelerfour@4.2.75 --typescript --output-folder=./generated/bodyComplex --use=. --title=BodyComplexClient --input-file=node_modules/@microsoft.azure/autorest.testserver/swagger/body-complex.json --package-name=bodyString --package-version=1.0.0-preview1" }, "dependencies": { - "@autorest/autorest": "^3.0.6122", + "@autorest/autorest": "^3.0.6146", "@azure-tools/async-io": "3.0.203", "@azure-tools/autorest-extension-base": "3.1.206", "@azure-tools/codegen": "2.1.218", @@ -23,7 +23,9 @@ "@azure-tools/linq": "3.1.206", "@azure-tools/openapi": "3.0.209", "@azure/core-http": "^1.0.0", - "@microsoft.azure/autorest.testserver": "^2.7.0", + "@microsoft.azure/autorest.testserver": "^2.7.1", + "@types/lodash": "^4.14.149", + "lodash": "^4.17.15", "prettier": "^1.19.1", "source-map-support": "^0.5.16", "ts-morph": "^5.0.0" From adfe289737ae595a8da8aabc60495a1a826ffd23 Mon Sep 17 00:00:00 2001 From: Jose Manuel Heredia Hidalgo Date: Tue, 10 Dec 2019 14:32:19 -0800 Subject: [PATCH 2/2] Support SealedChoice --- src/transforms/mapperTransforms.ts | 2 +- src/transforms/operationTransforms.ts | 1 + src/transforms/transforms.ts | 12 +++++++++--- src/utils/schemaHelpers.ts | 2 +- test/unit/utils/schemaHelpers.spec.ts | 9 +++------ 5 files changed, 15 insertions(+), 11 deletions(-) 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 }); });