Skip to content

Commit

Permalink
switch out from using the CfnRestApi.S3LocationProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
Niranjan Jayakar committed May 7, 2020
1 parent 68f693d commit 926f070
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions packages/@aws-cdk/aws-apigateway/lib/api-definition.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as s3 from '@aws-cdk/aws-s3';
import * as s3_assets from '@aws-cdk/aws-s3-assets';
import * as cdk from '@aws-cdk/core';
import { CfnRestApi } from './apigateway.generated';

/**
* Represents an OpenAPI definition asset.
Expand Down Expand Up @@ -38,27 +37,42 @@ export abstract class ApiDefinition {
public abstract bind(scope: cdk.Construct): ApiDefinitionConfig;
}

/**
* S3 location of the API definition file
*/
export interface ApiDefinitionS3Location {
/** The S3 bucket */
readonly bucket: string;
/** The S3 key */
readonly key: string;
/**
* An optional version
* @default - latest version
*/
readonly version?: string;
}

/**
* Post-Binding Configuration for a CDK construct
*/
export interface ApiDefinitionConfig {
/**
* The location of the specification in S3 (mutually exclusive with `inlineDefinition`).
*
* @default a new parameter will be created
* @default - API definition is not an S3 location
*/
readonly s3Location?: CfnRestApi.S3LocationProperty;
readonly s3Location?: ApiDefinitionS3Location;

/**
* Inline specification (mutually exclusive with `s3Location`).
*
* @default a new parameter will be created
* @default - API definition is not defined inline
*/
readonly inlineDefinition?: string;
}

/**
* Swagger/OpenAPI specification from an S3 archive
* OpenAPI specification from an S3 archive.
*/
export class S3ApiDefinition extends ApiDefinition {
private bucketName: string;
Expand All @@ -85,7 +99,7 @@ export class S3ApiDefinition extends ApiDefinition {
}

/**
* OpenAPI specification from an inline string (limited to 4KiB)
* OpenAPI specification from an inline string.
*/
export class InlineApiDefinition extends ApiDefinition {
constructor(private definition: string) {
Expand Down Expand Up @@ -122,14 +136,14 @@ export class AssetApiDefinition extends ApiDefinition {
});
}

if (this.asset?.isZipArchive) {
if (this.asset.isZipArchive) {
throw new Error(`Asset cannot be a .zip file or a directory (${this.path})`);
}

return {
s3Location: {
bucket: this.asset?.s3BucketName,
key: this.asset?.s3ObjectKey,
bucket: this.asset.s3BucketName,
key: this.asset.s3ObjectKey,
},
};
}
Expand Down

0 comments on commit 926f070

Please sign in to comment.