Skip to content

Commit

Permalink
fixed method responses duplication issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lpizzinidev committed Aug 11, 2023
1 parent 870a143 commit 5f8c797
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ class StepFunctionsExecutionIntegration extends AwsIntegration {
deploymentToken = JSON.stringify({ stateMachineName });
}

for (const methodResponse of METHOD_RESPONSES) {
method.addMethodResponse(methodResponse);
}
method.addMethodResponses(...METHOD_RESPONSES);

return {
...bindResult,
Expand Down
10 changes: 6 additions & 4 deletions packages/aws-cdk-lib/aws-apigateway/lib/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class Method extends Resource {
authorizer._attachToApi(this.api);
}

this.methodResponses = options.methodResponses ?? defaultMethodOptions.methodResponses ?? [];
this.methodResponses = options.methodResponses ? [...options.methodResponses] : defaultMethodOptions.methodResponses ?? [];

const integration = props.integration ?? this.resource.defaultIntegration ?? new MockIntegration();
const bindResult = integration.bind(this);
Expand Down Expand Up @@ -293,10 +293,12 @@ export class Method extends Resource {
}

/**
* Add a method response to this method
* Add method responses to this method if not already specified via options or by default
*/
public addMethodResponse(methodResponse: MethodResponse): void {
this.methodResponses.push(methodResponse);
public addMethodResponses(...methodResponse: MethodResponse[]): void {
if (this.methodResponses.length === 0) {
this.methodResponses.push(...methodResponse);
}
}

private renderIntegration(bindResult: IntegrationConfig): CfnMethod.IntegrationProperty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ describe('StepFunctionsIntegration', () => {

const integ = apigw.StepFunctionsIntegration.startExecution(stateMachine, integrationOptions);
api.root.addMethod('GET', integ, methodOptions);
// api.root.addMethod('POST', integ, methodOptions);
api.root.addMethod('POST', integ, methodOptions);

//THEN
Template.fromStack(stack).resourceCountIs('AWS::ApiGateway::Method', 2);
Expand Down

0 comments on commit 5f8c797

Please sign in to comment.