Skip to content

Commit

Permalink
fix(apigateway): deployment fails when Model's contentType is not spe…
Browse files Browse the repository at this point in the history
…cified (#6199)

CloudFormation and hence the CDK has marked this property as optional,
however, it is not. CloudFormation deployment will fail if this property
is not specified.

Use 'application/json' as the default as this is the most common case
when specifying the content type of the RestApi Model.

fixes #6161
  • Loading branch information
nija-at authored Feb 10, 2020
1 parent 491e2d9 commit 0bf1403
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface ModelOptions {
* The content type for the model. You can also force a
* content type in the request or response model mapping.
*
* @default -
* @default 'application/json'
*/
readonly contentType?: string;

Expand Down Expand Up @@ -167,7 +167,7 @@ export class Model extends Resource implements IModel {
const modelProps: CfnModelProps = {
name: this.physicalName,
restApiId: props.restApi.restApiId,
contentType: props.contentType,
contentType: props.contentType ?? 'application/json',
description: props.description,
schema: util.JsonSchemaMapper.toCfnJsonSchema(props.schema)
};
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-apigateway/test/test.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export = {
title: "test",
type: "object",
properties: { message: { type: "string" } }
}
},
ContentType: 'application/json'
}));

test.done();
Expand Down

0 comments on commit 0bf1403

Please sign in to comment.