Skip to content

Commit ac5a345

Browse files
authored
fix(apigateway): id in schema model maps to $id (#15113)
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 #14585 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent fbba9c7 commit ac5a345

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/@aws-cdk/aws-apigateway/lib/util.ts

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ export class JsonSchemaMapper {
101101
private static readonly SchemaPropsWithPrefix: { [key: string]: string } = {
102102
schema: '$schema',
103103
ref: '$ref',
104-
id: '$id',
105104
};
106105
// The value indicates whether direct children should be key-mapped.
107106
private static readonly SchemaPropsWithUserDefinedChildren: { [key: string]: boolean } = {

packages/@aws-cdk/aws-apigateway/test/util.test.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { JsonSchema, JsonSchemaType } from '../lib';
1+
import { JsonSchema, JsonSchemaType, JsonSchemaVersion } from '../lib';
22
import { JsonSchemaMapper, parseAwsApiCall, parseMethodOptionsPath } from '../lib/util';
33

44
describe('util', () => {
@@ -136,5 +136,18 @@ describe('util', () => {
136136
default: 'blue',
137137
});
138138
});
139+
140+
test('"id" maps to "id" when using DRAFT-04', () => {
141+
const schema: JsonSchema = {
142+
schema: JsonSchemaVersion.DRAFT4,
143+
id: 'http://json-schema.org/draft-04/schema#',
144+
};
145+
146+
const actual = JsonSchemaMapper.toCfnJsonSchema(schema);
147+
expect(actual).toEqual({
148+
$schema: 'http://json-schema.org/draft-04/schema#',
149+
id: 'http://json-schema.org/draft-04/schema#',
150+
});
151+
});
139152
});
140153
});

0 commit comments

Comments
 (0)