Skip to content

Commit

Permalink
Merge pull request Azure#16 from joheredi/support-sealed
Browse files Browse the repository at this point in the history
Support SealedChoice
  • Loading branch information
joheredi authored Dec 10, 2019
2 parents 428e384 + adfe289 commit 592c774
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@
"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",
"@azure-tools/codemodel": "3.0.239",
"@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"
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/mapperTransforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function transformMapper(obj: ObjectSchema): CompositeMapper {
serializedName,
required,
isConstant,
defaultValue,
...(defaultValue && { defaultValue }),
type: getMapperType(type)
});
});
Expand Down
1 change: 1 addition & 0 deletions src/transforms/operationTransforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions src/transforms/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
CodeModel,
ObjectSchema,
Property,
ChoiceSchema
ChoiceSchema,
SealedChoiceSchema
} from "@azure-tools/codemodel";
import {
normalizeName,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
};
}
2 changes: 1 addition & 1 deletion src/utils/schemaHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ export function getTypeForSchema(schema: Schema): PropertyTypeDetails {
return {
typeName,
isConstant: schema.type === SchemaType.Constant,
defaultValue
...(defaultValue && { defaultValue })
};
}
9 changes: 3 additions & 6 deletions test/unit/utils/schemaHelpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ describe("SchemaHelpers", () => {

assert.deepEqual(typeDetails, {
typeName: "string",
isConstant: false,
defaultValue: undefined
isConstant: false
});
});

Expand All @@ -34,8 +33,7 @@ describe("SchemaHelpers", () => {

assert.deepEqual(typeDetails, {
typeName: "number",
isConstant: false,
defaultValue: undefined
isConstant: false
});
});

Expand All @@ -51,8 +49,7 @@ describe("SchemaHelpers", () => {

assert.deepEqual(typeDetails, {
typeName: "number",
isConstant: false,
defaultValue: undefined
isConstant: false
});
});

Expand Down

0 comments on commit 592c774

Please sign in to comment.