Skip to content

Commit

Permalink
Support SealedChoice
Browse files Browse the repository at this point in the history
  • Loading branch information
joheredi committed Dec 10, 2019
1 parent a3aaf4e commit adfe289
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
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 adfe289

Please sign in to comment.