Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(apig): Move 'selectionPattern to integrationResponses` #1636

Merged
merged 1 commit into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions packages/@aws-cdk/aws-apigateway/lib/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,6 @@ export interface IntegrationOptions {
*/
integrationResponses?: IntegrationResponse[];

/**
* The templates that are used to transform the integration response body.
* Specify templates as key-value pairs (string-to-string mappings), with a
* content type as the key and a template as the value.
*
* @see http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
*/
selectionPattern?: string;

/**
* The type of network connection to the integration endpoint.
* @default ConnectionType.Internet
Expand Down Expand Up @@ -243,6 +234,17 @@ export enum ConnectionType {
}

export interface IntegrationResponse {
/**
* Specifies the regular expression (regex) pattern used to choose an integration response based on the response from
* the back end. For example, if the success response returns nothing and the error response returns some string, you
* could use the ``.+`` regex to match error response. However, make sure that the error response does not contain any
* newline (``\n``) character in such cases. If the back end is an AWS Lambda function, the AWS Lambda function error
* header is matched. For all other HTTP and AWS back ends, the HTTP status code is matched.
*
* @see https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-integration-settings-integration-response.html
*/
selectionPattern?: string;

/**
* The status code that API Gateway uses to map the integration response to
* a MethodResponse status code.
Expand Down
46 changes: 46 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/test.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,51 @@ export = {
// THEN
test.throws(() => api.root.addMethod('GET', integration), /cannot set 'vpcLink' where 'connectionType' is INTERNET/);
test.done();
},

'multiple integration responses can be used'(test: Test) { // @see https://github.com/awslabs/aws-cdk/issues/1608
// GIVEN
const stack = new cdk.Stack();
const api = new apigateway.RestApi(stack, 'test-api', { deploy: false });

// WHEN
api.root.addMethod('GET', new apigateway.AwsIntegration({
service: 'foo-service',
action: 'BarAction',
options: {
integrationResponses: [
{
statusCode: '200',
responseTemplates: { 'application/json': JSON.stringify({ success: true }) },
},
{
selectionPattern: 'Invalid',
statusCode: '503',
responseTemplates: { 'application/json': JSON.stringify({ success: false, message: 'Invalid Request' }) },
}
],
}
}));

// THEN
expect(stack).to(haveResource('AWS::ApiGateway::Method', {
Integration: {
IntegrationHttpMethod: 'POST',
IntegrationResponses: [
{
ResponseTemplates: { 'application/json': '{"success":true}' },
StatusCode: '200',
},
{
ResponseTemplates: { 'application/json': '{"success":false,"message":"Invalid Request"}' },
SelectionPattern: 'Invalid',
StatusCode: '503',
}
],
Type: 'AWS',
Uri: { 'Fn::Join': ['', ['arn:', { Ref: 'AWS::Partition' }, ':apigateway:', { Ref: 'AWS::Region' }, ':foo-service:action/BarAction']]}
}
}));
test.done();
}
};