Skip to content

Commit f37a525

Browse files
committed
add binaryMediaTypes to SpecRestApi
1 parent 6307e6f commit f37a525

File tree

11 files changed

+549
-17
lines changed

11 files changed

+549
-17
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.js.snapshot/apigatewayspecrestapiDefaultTestDeployAssertD16AA485.assets.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.js.snapshot/cdk.out

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.js.snapshot/integ.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.js.snapshot/manifest.json

Lines changed: 491 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.js.snapshot/test-apigateway-spec-restapi.assets.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.js.snapshot/test-apigateway-spec-restapi.template.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"myapi4C7BF186": {
44
"Type": "AWS::ApiGateway::RestApi",
55
"Properties": {
6+
"BinaryMediaTypes": [
7+
"image/png",
8+
"application/pdf"
9+
],
610
"BodyS3Location": {
711
"Bucket": {
812
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
@@ -518,7 +522,7 @@
518522
"UpdateReplacePolicy": "Retain",
519523
"DeletionPolicy": "Retain"
520524
},
521-
"myapiDeployment92F2CB491b0e40e722acabc99cc39958c957686d": {
525+
"myapiDeployment92F2CB49a6f2b34c48304b5ea39e505074a5a8ee": {
522526
"Type": "AWS::ApiGateway::Deployment",
523527
"Properties": {
524528
"Description": "beta stage",
@@ -550,7 +554,7 @@
550554
"CacheClusterEnabled": true,
551555
"CacheClusterSize": "0.5",
552556
"DeploymentId": {
553-
"Ref": "myapiDeployment92F2CB491b0e40e722acabc99cc39958c957686d"
557+
"Ref": "myapiDeployment92F2CB49a6f2b34c48304b5ea39e505074a5a8ee"
554558
},
555559
"Description": "beta stage",
556560
"MethodSettings": [

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.js.snapshot/tree.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Test extends cdk.Stack {
1414
apiDefinition: apigateway.ApiDefinition.fromAsset(path.join(__dirname, 'sample-definition.yaml')),
1515
disableExecuteApiEndpoint: true,
1616
minCompressionSize: Size.bytes(1024),
17+
binaryMediaTypes: ['image/png', 'application/pdf'],
1718
retainDeployments: true,
1819
cloudWatchRole: true,
1920
deployOptions: {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,15 @@ const api = new apigateway.SpecRestApi(this, 'books-api', {
16521652
});
16531653
```
16541654

1655+
`SpecRestApi` also supports binary media types, similar to `RestApi`:
1656+
1657+
```ts
1658+
const api = new apigateway.SpecRestApi(this, 'books-api', {
1659+
apiDefinition: apigateway.ApiDefinition.fromAsset('path-to-file.json'),
1660+
binaryMediaTypes: ['image/png', 'application/pdf']
1661+
});
1662+
```
1663+
16551664
### Endpoint configuration
16561665

16571666
By default, `SpecRestApi` will create an edge optimized endpoint.

packages/aws-cdk-lib/aws-apigateway/lib/restapi.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ export interface SpecRestApiProps extends RestApiBaseProps {
332332
* @default - `merge` for REST APIs created after March 29, 2021, otherwise `overwrite`
333333
*/
334334
readonly mode?: RestApiMode;
335+
/**
336+
* The list of binary media types supported by the RestApi. By default, the RestApi supports only UTF-8-encoded text payloads.
337+
*
338+
* @default - RestApi supports only UTF-8-encoded text payloads.
339+
*/
340+
readonly binaryMediaTypes?: string[];
335341
}
336342

337343
/**
@@ -802,6 +808,7 @@ export class SpecRestApi extends RestApiBase {
802808
policy: Lazy.any({ produce: () => this.resourcePolicy }),
803809
failOnWarnings: props.failOnWarnings,
804810
minimumCompressionSize: props.minCompressionSize?.toBytes(),
811+
binaryMediaTypes: props.binaryMediaTypes,
805812
body: apiDefConfig.inlineDefinition ?? undefined,
806813
bodyS3Location: apiDefConfig.inlineDefinition ? undefined : apiDefConfig.s3Location,
807814
endpointConfiguration: this._configureEndpoints(props),

0 commit comments

Comments
 (0)