Skip to content

Commit

Permalink
chore(apigatewayv2): rename 'domainName' to 'name' in the DomainName …
Browse files Browse the repository at this point in the history
…construct (aws#11989)

C# does not allow a property to have the same name as its class.
Jsii works around this by renaming the construct to `_DomainName` which
is ugly.

Instead, change the property name from `domainName` to `name` and avoid
this conflict entirely.

Further, re-categorize these class of defects as an error instead of a
warning.

BREAKING CHANGE: `domainName` property under `DomainName` has been
renamed to `name`.

----

*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 and flochaz committed Jan 5, 2021
1 parent 8c55fac commit 361e467
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 26 deletions.
29 changes: 6 additions & 23 deletions packages/@aws-cdk/aws-apigatewayv2/lib/common/domain-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ import { CfnDomainName, CfnDomainNameProps } from '../apigatewayv2.generated';
export interface IDomainName extends IResource {
/**
* The custom domain name
*
* @attribute
*
*/
readonly domainName: string;
readonly name: string;

/**
* The domain name associated with the regional endpoint for this custom domain name.
*
* @attribute
*/
readonly regionalDomainName: string;

/**
* The region-specific Amazon Route 53 Hosted Zone ID of the regional endpoint.
*
* @attribute
*/
readonly regionalHostedZoneId: string;
Expand All @@ -38,7 +34,7 @@ export interface DomainNameAttributes {
/**
* domain name string
*/
readonly domainName: string;
readonly name: string;

/**
* The domain name associated with the regional endpoint for this custom domain name.
Expand Down Expand Up @@ -70,32 +66,19 @@ export interface DomainNameProps {
*/
export class DomainName extends Resource implements IDomainName {
/**
* import from attributes
* Import from attributes
*/
public static fromDomainNameAttributes(scope: Construct, id: string, attrs: DomainNameAttributes): IDomainName {
class Import extends Resource implements IDomainName {
public readonly regionalDomainName = attrs.regionalDomainName;
public readonly regionalHostedZoneId = attrs.regionalHostedZoneId;
public readonly domainName = attrs.domainName;
public readonly name = attrs.name;
}
return new Import(scope, id);
}

/**
* The custom domain name for your API in Amazon API Gateway.
*
* @attribute
*/
public readonly domainName: string;

/**
* The domain name associated with the regional endpoint for this custom domain name.
*/
public readonly name: string;
public readonly regionalDomainName: string;

/**
* The region-specific Amazon Route 53 Hosted Zone ID of the regional endpoint.
*/
public readonly regionalHostedZoneId: string;

constructor(scope: Construct, id: string, props: DomainNameProps) {
Expand All @@ -111,7 +94,7 @@ export class DomainName extends Resource implements IDomainName {
],
};
const resource = new CfnDomainName(this, 'Resource', domainNameProps);
this.domainName = props.domainName ?? resource.ref;
this.name = props.domainName ?? resource.ref;
this.regionalDomainName = Token.asString(resource.getAtt('RegionalDomainName'));
this.regionalHostedZoneId = Token.asString(resource.getAtt('RegionalHostedZoneId'));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigatewayv2/lib/http/api-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class HttpApiMapping extends Resource implements IApiMapping {

const apiMappingProps: CfnApiMappingProps = {
apiId: props.api.httpApiId,
domainName: props.domainName.domainName,
domainName: props.domainName.name,
stage: props.stage?.stageName ?? props.api.defaultStage!.stageName,
apiMappingKey: props.apiMappingKey,
};
Expand Down
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-apigatewayv2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"types": "lib/index.d.ts",
"jsii": {
"outdir": "dist",
"diagnostics": {
"language-compatibility/member-name-conflicts-with-type-name": "error",
"language-compatibility/reserved-word": "error"
},
"targets": {
"dotnet": {
"namespace": "Amazon.CDK.AWS.APIGatewayv2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ describe('DomainName', () => {

// WHEN
const imported = DomainName.fromDomainNameAttributes(stack, 'dn', {
domainName: dn.domainName,
name: dn.name,
regionalDomainName: dn.regionalDomainName,
regionalHostedZoneId: dn.regionalHostedZoneId,
});

// THEN;
expect(imported.domainName).toEqual(dn.domainName);
expect(imported.name).toEqual(dn.name);
expect(imported.regionalDomainName).toEqual(dn.regionalDomainName);
expect(imported.regionalHostedZoneId).toEqual(dn.regionalHostedZoneId);
});
Expand Down

0 comments on commit 361e467

Please sign in to comment.