Skip to content

Commit bf10d94

Browse files
authored
feat(apigateway): add binaryMediaTypes property to SpecRestApi (#35502)
### Issue #35498 ### Reason for this change The `SpecRestApi` construct was missing the `binaryMediaTypes` property that is available in the regular `RestApi` construct. ### Description of changes - Added `binaryMediaTypes` property to `SpecRestApiProps` interface**: This property accepts an array of strings representing binary media types (e.g., `['image/png', 'application/pdf']`) - Updated `SpecRestApi` constructor**: Modified to pass the `binaryMediaTypes` property to the underlying `CfnRestApi` resource - Updated README documentation: Added usage example showing how to use `binaryMediaTypes` with `SpecRestApi` ### Describe any new or updated permissions being added N/A ### Description of how you validated changes - Added unit tests: Created tests to verify that the `binaryMediaTypes` property is correctly passed to CloudFormation - Added integration tests: Updated existing integration test to include `binaryMediaTypes` configuration ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 5dec21e commit bf10d94

File tree

11 files changed

+551
-17
lines changed

11 files changed

+551
-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ export interface SpecRestApiProps extends RestApiBaseProps {
300300
*/
301301
readonly apiDefinition: ApiDefinition;
302302

303+
/**
304+
* The list of binary media mime-types that are supported by the SpecRestApi
305+
* resource, such as "image/png" or "application/octet-stream"
306+
*
307+
* @default - SpecRestApi supports only UTF-8-encoded text payloads.
308+
*/
309+
readonly binaryMediaTypes?: string[];
310+
303311
/**
304312
* A Size(in bytes, kibibytes, mebibytes etc) that is used to enable compression (with non-negative
305313
* between 0 and 10485760 (10M) bytes, inclusive) or disable compression
@@ -802,6 +810,7 @@ export class SpecRestApi extends RestApiBase {
802810
policy: Lazy.any({ produce: () => this.resourcePolicy }),
803811
failOnWarnings: props.failOnWarnings,
804812
minimumCompressionSize: props.minCompressionSize?.toBytes(),
813+
binaryMediaTypes: props.binaryMediaTypes,
805814
body: apiDefConfig.inlineDefinition ?? undefined,
806815
bodyS3Location: apiDefConfig.inlineDefinition ? undefined : apiDefConfig.s3Location,
807816
endpointConfiguration: this._configureEndpoints(props),

0 commit comments

Comments
 (0)