Skip to content

Commit

Permalink
chore(apigatewayv2): remove dependency of "http" from "common" (#17715)
Browse files Browse the repository at this point in the history
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Niranjan Jayakar authored Nov 25, 2021
1 parent 9d436a0 commit b8a4a9a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
17 changes: 6 additions & 11 deletions packages/@aws-cdk/aws-apigatewayv2/lib/common/api-mapping.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IResource, Resource } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnApiMapping, CfnApiMappingProps } from '../apigatewayv2.generated';
import { HttpApi } from '../http/api';
import { IApi } from './api';
import { IDomainName } from './domain-name';
import { IStage } from './stage';
Expand Down Expand Up @@ -90,17 +89,13 @@ export class ApiMapping extends Resource implements IApiMapping {
constructor(scope: Construct, id: string, props: ApiMappingProps) {
super(scope, id);

let stage = props.stage;
// defaultStage is present in IHttpStage.
// However, importing "http" or "websocket" must import "common", but creating dependencies
// the other way will cause potential cycles.
// So casting to 'any'
let stage = props.stage ?? (props.api as any).defaultStage;
if (!stage) {
if (props.api instanceof HttpApi) {
if (props.api.defaultStage) {
stage = props.api.defaultStage;
} else {
throw new Error('stage is required if default stage is not available');
}
} else {
throw new Error('stage is required for WebSocket API');
}
throw new Error('stage property must be specified');
}

if (props.apiMappingKey === '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('ApiMapping', () => {
api,
domainName: dn,
});
}).toThrow(/stage is required if default stage is not available/);
}).toThrow(/stage property must be specified/);
});

test('stage validation - throws if stage not provided for WebSocketApi', () => {
Expand All @@ -138,6 +138,6 @@ describe('ApiMapping', () => {
api,
domainName: dn,
});
}).toThrow(/stage is required for WebSocket API/);
}).toThrow(/stage property must be specified/);
});
});

0 comments on commit b8a4a9a

Please sign in to comment.