-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cors): maps all unique operation mime types in cors preflight
closes #2289
- Loading branch information
Showing
5 changed files
with
360 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...t/resources/software/amazon/smithy/aws/apigateway/openapi/cors-with-multi-mime-types.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{ | ||
"smithy": "2.0", | ||
"shapes": { | ||
"example.smithy#MyService": { | ||
"type": "service", | ||
"version": "2006-03-01", | ||
"operations": [ | ||
{ | ||
"target": "example.smithy#MockPut" | ||
}, | ||
{ | ||
"target": "example.smithy#MockGet" | ||
} | ||
], | ||
"traits": { | ||
"aws.protocols#restJson1": {}, | ||
"aws.auth#sigv4": { | ||
"name": "myservice" | ||
}, | ||
"smithy.api#cors": { | ||
"origin": "https://www.example.com", | ||
"maxAge": 86400, | ||
"additionalAllowedHeaders": [ | ||
"X-Service-Input-Metadata" | ||
], | ||
"additionalExposedHeaders": [ | ||
"X-Service-Output-Metadata" | ||
] | ||
} | ||
} | ||
}, | ||
"example.smithy#MockGet": { | ||
"type": "operation", | ||
"output": { | ||
"target": "example.smithy#MockOutput" | ||
}, | ||
"traits": { | ||
"aws.apigateway#mockIntegration": { | ||
"passThroughBehavior": "never", | ||
"requestTemplates": { | ||
"application/json": "{\"statusCode\": 200}", | ||
"application/x-www-form-urlencoded": "{\"statusCode\": 200}" | ||
}, | ||
"responses": { | ||
"default": { | ||
"statusCode": "200", | ||
"responseTemplates": { | ||
"application/json": "{\"extendedRequestId\": \"$context.extendedRequestId\"}" | ||
} | ||
} | ||
} | ||
}, | ||
"smithy.api#http": { | ||
"code": 200, | ||
"method": "GET", | ||
"uri": "/mock" | ||
}, | ||
"smithy.api#readonly": {} | ||
} | ||
}, | ||
"example.smithy#MockPut": { | ||
"type": "operation", | ||
"output": { | ||
"target": "example.smithy#MockOutput" | ||
}, | ||
"traits": { | ||
"aws.apigateway#mockIntegration": { | ||
"passThroughBehavior": "never", | ||
"requestTemplates": { | ||
"text/plain": "{\"statusCode\": 200}", | ||
"application/xml": "{\"statusCode\": 200}" | ||
}, | ||
"responses": { | ||
"default": { | ||
"statusCode": "200", | ||
"responseTemplates": { | ||
"application/json": "{\"extendedRequestId\": \"$context.extendedRequestId\"}" | ||
} | ||
} | ||
} | ||
}, | ||
"smithy.api#http": { | ||
"code": 201, | ||
"method": "PUT", | ||
"uri": "/mock" | ||
}, | ||
"smithy.api#idempotent": {} | ||
} | ||
}, | ||
"example.smithy#MockOutput": { | ||
"type": "structure", | ||
"members": { | ||
"extendedRequestId": { | ||
"target": "smithy.api#String", | ||
"traits": { | ||
"smithy.api#required": {} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
222 changes: 222 additions & 0 deletions
222
...ces/software/amazon/smithy/aws/apigateway/openapi/cors-with-multi-mime-types.openapi.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
{ | ||
"openapi": "3.0.2", | ||
"info": { | ||
"title": "MyService", | ||
"version": "2006-03-01" | ||
}, | ||
"paths": { | ||
"/mock": { | ||
"get": { | ||
"operationId": "MockGet", | ||
"responses": { | ||
"200": { | ||
"description": "MockGet 200 response", | ||
"headers": { | ||
"Access-Control-Allow-Origin": { | ||
"schema": { | ||
"type": "string" | ||
} | ||
}, | ||
"Access-Control-Expose-Headers": { | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/MockGetResponseContent" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"x-amazon-apigateway-integration": { | ||
"requestTemplates": { | ||
"application/json": "{\"statusCode\": 200}", | ||
"application/x-www-form-urlencoded": "{\"statusCode\": 200}" | ||
}, | ||
"responses": { | ||
"default": { | ||
"statusCode": "200", | ||
"responseTemplates": { | ||
"application/json": "{\"extendedRequestId\": \"$context.extendedRequestId\"}" | ||
}, | ||
"responseParameters": { | ||
"method.response.header.Access-Control-Allow-Origin": "'https://www.example.com'", | ||
"method.response.header.Access-Control-Expose-Headers": "'Content-Length,Content-Type,X-Amzn-Errortype,X-Amzn-Requestid,X-Service-Output-Metadata'" | ||
} | ||
} | ||
}, | ||
"type": "mock", | ||
"passthroughBehavior": "never" | ||
} | ||
}, | ||
"options": { | ||
"description": "Handles CORS-preflight requests", | ||
"operationId": "CorsMock", | ||
"responses": { | ||
"200": { | ||
"description": "Canned response for CORS-preflight requests", | ||
"headers": { | ||
"Access-Control-Allow-Headers": { | ||
"schema": { | ||
"type": "string" | ||
} | ||
}, | ||
"Access-Control-Allow-Methods": { | ||
"schema": { | ||
"type": "string" | ||
} | ||
}, | ||
"Access-Control-Allow-Origin": { | ||
"schema": { | ||
"type": "string" | ||
} | ||
}, | ||
"Access-Control-Max-Age": { | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"security": [], | ||
"tags": [ | ||
"CORS" | ||
], | ||
"x-amazon-apigateway-integration": { | ||
"contentHandling": "CONVERT_TO_TEXT", | ||
"requestTemplates": { | ||
"application/xml": "{\"statusCode\":200}", | ||
"application/x-www-form-urlencoded": "{\"statusCode\":200}", | ||
"application/json": "{\"statusCode\":200}", | ||
"text/plain": "{\"statusCode\":200}" | ||
}, | ||
"responses": { | ||
"default": { | ||
"responseParameters": { | ||
"method.response.header.Access-Control-Max-Age": "'86400'", | ||
"method.response.header.Access-Control-Allow-Headers": "'Amz-Sdk-Invocation-Id,Amz-Sdk-Request,Authorization,Date,Host,X-Amz-Content-Sha256,X-Amz-Date,X-Amz-Security-Token,X-Amz-Target,X-Amz-User-Agent,X-Amzn-Trace-Id,X-Service-Input-Metadata'", | ||
"method.response.header.Access-Control-Allow-Origin": "'https://www.example.com'", | ||
"method.response.header.Access-Control-Allow-Methods": "'GET,PUT'" | ||
}, | ||
"statusCode": "200" | ||
} | ||
}, | ||
"type": "mock", | ||
"passthroughBehavior": "when_no_match" | ||
} | ||
}, | ||
"put": { | ||
"operationId": "MockPut", | ||
"responses": { | ||
"201": { | ||
"description": "MockPut 201 response", | ||
"headers": { | ||
"Access-Control-Allow-Origin": { | ||
"schema": { | ||
"type": "string" | ||
} | ||
}, | ||
"Access-Control-Expose-Headers": { | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/MockPutResponseContent" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"x-amazon-apigateway-integration": { | ||
"requestTemplates": { | ||
"text/plain": "{\"statusCode\": 200}", | ||
"application/xml": "{\"statusCode\": 200}" | ||
}, | ||
"responses": { | ||
"default": { | ||
"statusCode": "200", | ||
"responseTemplates": { | ||
"application/json": "{\"extendedRequestId\": \"$context.extendedRequestId\"}" | ||
}, | ||
"responseParameters": { | ||
"method.response.header.Access-Control-Allow-Origin": "'https://www.example.com'", | ||
"method.response.header.Access-Control-Expose-Headers": "'Content-Length,Content-Type,X-Amzn-Errortype,X-Amzn-Requestid,X-Service-Output-Metadata'" | ||
} | ||
} | ||
}, | ||
"type": "mock", | ||
"passthroughBehavior": "never" | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"MockGetResponseContent": { | ||
"type": "object", | ||
"properties": { | ||
"extendedRequestId": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"extendedRequestId" | ||
] | ||
}, | ||
"MockPutResponseContent": { | ||
"type": "object", | ||
"properties": { | ||
"extendedRequestId": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"extendedRequestId" | ||
] | ||
} | ||
}, | ||
"securitySchemes": { | ||
"aws.auth.sigv4": { | ||
"type": "apiKey", | ||
"description": "AWS Signature Version 4 authentication", | ||
"name": "Authorization", | ||
"in": "header", | ||
"x-amazon-apigateway-authtype": "awsSigv4" | ||
} | ||
} | ||
}, | ||
"security": [ | ||
{ | ||
"aws.auth.sigv4": [ ] | ||
} | ||
], | ||
"x-amazon-apigateway-gateway-responses": { | ||
"DEFAULT_4XX": { | ||
"responseTemplates": { | ||
"application/json": "{\"message\":$context.error.messageString}" | ||
}, | ||
"responseParameters": { | ||
"gatewayresponse.header.Access-Control-Allow-Origin": "'https://www.example.com'", | ||
"gatewayresponse.header.Access-Control-Expose-Headers": "'X-Service-Output-Metadata'" | ||
} | ||
}, | ||
"DEFAULT_5XX": { | ||
"responseTemplates": { | ||
"application/json": "{\"message\":$context.error.messageString}" | ||
}, | ||
"responseParameters": { | ||
"gatewayresponse.header.Access-Control-Allow-Origin": "'https://www.example.com'", | ||
"gatewayresponse.header.Access-Control-Expose-Headers": "'X-Service-Output-Metadata'" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.