From 06842d6389c8216bbfd18a397ef3d6f3b15316fb Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Thu, 16 Jul 2020 11:55:28 +0100 Subject: [PATCH] chore(apigateway): remove default* properties from SpecRestApi (#9099) SpecRestApiProps contained `defaultMethodOptions`, `defaultCorsPreflightOptions` and `defaultIntegration` as properties. However, these defaults are only applied to Methods and Resources defined via addMethod() and addResource() APIs. These do *not* apply to Resources and Methods defined in the OpenAPI spec. Users have complained that this is unclear [1] [2]. This PR removes these options from the constructor properties of `SpecRestApi`. Users can still specify these when adding new Resources and new Methods. These options don't make much sense to be specified on a `SpecRestApi` since they cannot be applied to the Resources and Methods in the OpenAPI spec. This will match up with the functionality available. closes #8347 [1]: https://github.com/aws/aws-cdk/issues/8347#issuecomment-651900511 [2]: https://github.com/aws/aws-cdk/issues/8347#issuecomment-652779763 BREAKING CHANGE: `defaultMethodOptions`, `defaultCorsPreflightOptions` and `defaultIntegration` have been removed from `SpecRestApiProps`. These can be specifed directly in the OpenAPI spec or via `addMethod()` and `addResource()` APIs. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-apigateway/lib/restapi.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts index 9ba3714aed915..cedf43099856e 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts @@ -67,7 +67,7 @@ export interface IRestApi extends IResourceBase { /** * Represents the props that all Rest APIs share */ -export interface RestApiOptions extends ResourceOptions { +export interface RestApiBaseProps { /** * Indicates if a Deployment should be automatically created for this API, * and recreated when the API model (resources, methods) changes. @@ -161,6 +161,13 @@ export interface RestApiOptions extends ResourceOptions { readonly endpointExportName?: string; } +/** + * Represents the props that all Rest APIs share. + * @deprecated - superceded by `RestApiBaseProps` + */ +export interface RestApiOptions extends RestApiBaseProps, ResourceOptions { +} + /** * Props to create a new instance of RestApi */ @@ -229,7 +236,7 @@ export interface RestApiProps extends RestApiOptions { * Props to instantiate a new SpecRestApi * @experimental */ -export interface SpecRestApiProps extends RestApiOptions { +export interface SpecRestApiProps extends RestApiBaseProps { /** * An OpenAPI definition compatible with API Gateway. * @see https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-import-api.html @@ -296,7 +303,7 @@ export abstract class RestApiBase extends Resource implements IRestApi { private _latestDeployment?: Deployment; private _domainName?: DomainName; - constructor(scope: Construct, id: string, props: RestApiOptions = { }) { + constructor(scope: Construct, id: string, props: RestApiBaseProps = { }) { super(scope, id, { physicalName: props.restApiName || id, }); @@ -461,7 +468,7 @@ export class SpecRestApi extends RestApiBase { this.node.defaultChild = resource; this.restApiId = resource.ref; this.restApiRootResourceId = resource.attrRootResourceId; - this.root = new RootResource(this, props, this.restApiRootResourceId); + this.root = new RootResource(this, {}, this.restApiRootResourceId); this.configureDeployment(props); if (props.domainName) {