Skip to content

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
"ProtocolType": "WEBSOCKET",
"RouteSelectionExpression": "$request.body.action"
}
},
"WebSocketApiWithProps9DA8D44F": {
"Type": "AWS::ApiGatewayV2::Api",
"Properties": {
"DisableSchemaValidation": true,
"Name": "WebSocketApiWithProps",
"ProtocolType": "WEBSOCKET",
"RouteSelectionExpression": "$request.body.action"
}
}
},
"Parameters": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const stack = new cdk.Stack(app, 'aws-cdk-aws-apigatewayv2');

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

new apigw.WebSocketApi(stack, 'WebSocketApiWithProps', {
disableSchemaValidation: true,
});

new IntegTest(app, 'web-socket-api', {
testCases: [stack],
});
Expand Down
8 changes: 8 additions & 0 deletions packages/aws-cdk-lib/aws-apigatewayv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,14 @@ const api = new apigwv2.WebSocketApi(this, 'mywsapi');
const arn = api.arnForExecuteApiV2('$connect', 'dev');
```

To disable schema validation, set `disableSchemaValidation` to true.

```ts
new apigwv2.WebSocketApi(this, 'api', {
disableSchemaValidation: true,
});
```

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line refers to the arnForExecuteApiV2.
The example and explanation for arnForExecuteApiV2 are separated by the disableSchemaValidation sentences, which should be relocated to improve readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Moved the disableSchemaValidation explanation to its own section to avoid interrupting the arnForExecuteApiV2 example and description flow.


You can configure IP address type for the API endpoint using `ipAddressType` property.
Expand Down
9 changes: 9 additions & 0 deletions packages/aws-cdk-lib/aws-apigatewayv2/lib/websocket/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ export interface WebSocketApiProps {
* @default undefined - AWS default is IPV4
*/
readonly ipAddressType?: IpAddressType;

/**
* Avoid validating models when creating a deployment.
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-apigatewayv2-api.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of adding this link?
It seems that this link is not specific to the adding property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
I misunderstood the condition for when links are necessary, so I removed the redundant link.

*
* @default false
*/
readonly disableSchemaValidation?: boolean;
}

/**
Expand Down Expand Up @@ -162,6 +170,7 @@ export class WebSocketApi extends ApiBase implements IWebSocketApi {
description: props?.description,
routeSelectionExpression: props?.routeSelectionExpression ?? '$request.body.action',
ipAddressType: props?.ipAddressType,
disableSchemaValidation: props?.disableSchemaValidation,
});
this.apiId = resource.ref;
this.apiEndpoint = resource.attrApiEndpoint;
Expand Down
15 changes: 15 additions & 0 deletions packages/aws-cdk-lib/aws-apigatewayv2/test/websocket/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,21 @@ describe('WebSocketApi', () => {
IpAddressType: ipAddressType,
});
});

test.each([true, false, undefined])('disableSchemaValidation is set to %s', (disableSchemaValidation) => {
const stack = new Stack();
new WebSocketApi(stack, 'api', {
disableSchemaValidation,
});

const value = disableSchemaValidation !== undefined ? disableSchemaValidation : Match.absent();

Template.fromStack(stack).hasResourceProperties('AWS::ApiGatewayV2::Api', {
Name: 'api',
ProtocolType: 'WEBSOCKET',
DisableSchemaValidation: value,
});
});
});

class DummyIntegration extends WebSocketRouteIntegration {
Expand Down
Loading