Skip to content

Commit cdb39c2

Browse files
committed
feat(apigatewayv2): add disableSchemaValidation for websocket api
1 parent 2741dfb commit cdb39c2

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/websocket/integ.api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const stack = new cdk.Stack(app, 'aws-cdk-aws-apigatewayv2');
88

99
new apigw.WebSocketApi(stack, 'WebSocketApi');
1010

11+
new apigw.WebSocketApi(stack, 'WebSocketApiWithProps', {
12+
disableSchemaValidation: true,
13+
});
14+
1115
new IntegTest(app, 'web-socket-api', {
1216
testCases: [stack],
1317
});

packages/aws-cdk-lib/aws-apigatewayv2/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,14 @@ const api = new apigwv2.WebSocketApi(this, 'mywsapi');
522522
const arn = api.arnForExecuteApiV2('$connect', 'dev');
523523
```
524524

525+
To disable schema validation, set `disableSchemaValidation` to true.
526+
527+
```ts
528+
new apigwv2.WebSocketApi(this, 'api', {
529+
disableSchemaValidation: true,
530+
});
531+
```
532+
525533
For a detailed explanation of this function, including usage and examples, please refer to the [Generating ARN for Execute API](#generating-arn-for-execute-api) section under HTTP API.
526534

527535
You can configure IP address type for the API endpoint using `ipAddressType` property.

packages/aws-cdk-lib/aws-apigatewayv2/lib/websocket/api.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ export interface WebSocketApiProps {
9494
* @default undefined - AWS default is IPV4
9595
*/
9696
readonly ipAddressType?: IpAddressType;
97+
98+
/**
99+
* Avoid validating models when creating a deployment.
100+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-apigatewayv2-api.html
101+
*
102+
* @default false
103+
*/
104+
readonly disableSchemaValidation?: boolean;
97105
}
98106

99107
/**
@@ -162,6 +170,7 @@ export class WebSocketApi extends ApiBase implements IWebSocketApi {
162170
description: props?.description,
163171
routeSelectionExpression: props?.routeSelectionExpression ?? '$request.body.action',
164172
ipAddressType: props?.ipAddressType,
173+
disableSchemaValidation: props?.disableSchemaValidation,
165174
});
166175
this.apiId = resource.ref;
167176
this.apiEndpoint = resource.attrApiEndpoint;

packages/aws-cdk-lib/aws-apigatewayv2/test/websocket/api.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,21 @@ describe('WebSocketApi', () => {
307307
IpAddressType: ipAddressType,
308308
});
309309
});
310+
311+
test.each([true, false, undefined])('disableSchemaValidation is set to %s', (disableSchemaValidation) => {
312+
const stack = new Stack();
313+
new WebSocketApi(stack, 'api', {
314+
disableSchemaValidation,
315+
});
316+
317+
const value = disableSchemaValidation !== undefined ? disableSchemaValidation : Match.absent();
318+
319+
Template.fromStack(stack).hasResourceProperties('AWS::ApiGatewayV2::Api', {
320+
Name: 'api',
321+
ProtocolType: 'WEBSOCKET',
322+
DisableSchemaValidation: value,
323+
});
324+
})
310325
});
311326

312327
class DummyIntegration extends WebSocketRouteIntegration {

0 commit comments

Comments
 (0)