Skip to content

Commit

Permalink
fix(apigateway): id in schema model maps to $id (aws#15113)
Browse files Browse the repository at this point in the history
If we specify the `id` field when defining an Api Gateway Model's schema, it gets mapped to a `$id` key, which creates an invalid model because it doesn't comply with the DRAFT-04 specification. The specification requires this field to remain named as `id`.

fixes aws#14585


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jihndai authored and Stephen Potter committed Apr 27, 2022
1 parent 91d3383 commit 7b68367
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 0 additions & 1 deletion packages/@aws-cdk/aws-apigateway/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export class JsonSchemaMapper {
private static readonly SchemaPropsWithPrefix: { [key: string]: string } = {
schema: '$schema',
ref: '$ref',
id: '$id',
};
// The value indicates whether direct children should be key-mapped.
private static readonly SchemaPropsWithUserDefinedChildren: { [key: string]: boolean } = {
Expand Down
15 changes: 14 additions & 1 deletion packages/@aws-cdk/aws-apigateway/test/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JsonSchema, JsonSchemaType } from '../lib';
import { JsonSchema, JsonSchemaType, JsonSchemaVersion } from '../lib';
import { JsonSchemaMapper, parseAwsApiCall, parseMethodOptionsPath } from '../lib/util';

describe('util', () => {
Expand Down Expand Up @@ -136,5 +136,18 @@ describe('util', () => {
default: 'blue',
});
});

test('"id" maps to "id" when using DRAFT-04', () => {
const schema: JsonSchema = {
schema: JsonSchemaVersion.DRAFT4,
id: 'http://json-schema.org/draft-04/schema#',
};

const actual = JsonSchemaMapper.toCfnJsonSchema(schema);
expect(actual).toEqual({
$schema: 'http://json-schema.org/draft-04/schema#',
id: 'http://json-schema.org/draft-04/schema#',
});
});
});
});

0 comments on commit 7b68367

Please sign in to comment.