Skip to content

Commit

Permalink
feat(apigateway): default value for enum type in schema models (#11064)
Browse files Browse the repository at this point in the history
Fixes: #11065
Add default to JsonSchema


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
mmuller88 authored Nov 6, 2020
1 parent dfbf97b commit 9eff751
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/@aws-cdk/aws-apigateway/lib/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export interface JsonSchema {
readonly title?: string;
readonly description?: string;
readonly 'enum'?: any[];
/**
* The default value if you use an enum.
*
* @default - not set
*/
readonly default?: any;
readonly format?: string;
readonly definitions?: { [name: string]: JsonSchema };

Expand Down
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,21 @@ describe('util', () => {
required: ['ref'],
});
});

test('"default" for enum', () => {
const schema: JsonSchema = {
type: JsonSchemaType.STRING,
enum: ['green', 'blue', 'red'],
default: 'blue',
};

const actual = JsonSchemaMapper.toCfnJsonSchema(schema);
expect(actual).toEqual({
$schema: 'http://json-schema.org/draft-04/schema#',
type: 'string',
enum: ['green', 'blue', 'red'],
default: 'blue',
});
});
});
});

0 comments on commit 9eff751

Please sign in to comment.