UNPKG

4.48 kBTypeScriptView Raw
1import * as s3 from '@aws-cdk/aws-s3';
2import * as s3_assets from '@aws-cdk/aws-s3-assets';
3import { IRestApi } from './restapi';
4import { Construct } from '@aws-cdk/core';
5/**
6 * Represents an OpenAPI definition asset.
7 */
8export declare abstract class ApiDefinition {
9 /**
10 * Creates an API definition from a specification file in an S3 bucket
11 */
12 static fromBucket(bucket: s3.IBucket, key: string, objectVersion?: string): S3ApiDefinition;
13 /**
14 * Create an API definition from an inline object. The inline object must follow the
15 * schema of OpenAPI 2.0 or OpenAPI 3.0
16 *
17 * @example
18 *
19 * apigateway.ApiDefinition.fromInline({
20 * openapi: '3.0.2',
21 * paths: {
22 * '/pets': {
23 * get: {
24 * 'responses': {
25 * 200: {
26 * content: {
27 * 'application/json': {
28 * schema: {
29 * $ref: '#/components/schemas/Empty',
30 * },
31 * },
32 * },
33 * },
34 * },
35 * 'x-amazon-apigateway-integration': {
36 * responses: {
37 * default: {
38 * statusCode: '200',
39 * },
40 * },
41 * requestTemplates: {
42 * 'application/json': '{"statusCode": 200}',
43 * },
44 * passthroughBehavior: 'when_no_match',
45 * type: 'mock',
46 * },
47 * },
48 * },
49 * },
50 * components: {
51 * schemas: {
52 * Empty: {
53 * title: 'Empty Schema',
54 * type: 'object',
55 * },
56 * },
57 * },
58 * });
59 */
60 static fromInline(definition: any): InlineApiDefinition;
61 /**
62 * Loads the API specification from a local disk asset.
63 */
64 static fromAsset(file: string, options?: s3_assets.AssetOptions): AssetApiDefinition;
65 /**
66 * Called when the specification is initialized to allow this object to bind
67 * to the stack, add resources and have fun.
68 *
69 * @param scope The binding scope. Don't be smart about trying to down-cast or
70 * assume it's initialized. You may just use it as a construct scope.
71 */
72 abstract bind(scope: Construct): ApiDefinitionConfig;
73 /**
74 * Called after the CFN RestApi resource has been created to allow the Api
75 * Definition to bind to it. Specifically it's required to allow assets to add
76 * metadata for tooling like SAM CLI to be able to find their origins.
77 */
78 bindAfterCreate(_scope: Construct, _restApi: IRestApi): void;
79}
80/**
81 * S3 location of the API definition file
82 */
83export interface ApiDefinitionS3Location {
84 /** The S3 bucket */
85 readonly bucket: string;
86 /** The S3 key */
87 readonly key: string;
88 /**
89 * An optional version
90 * @default - latest version
91 */
92 readonly version?: string;
93}
94/**
95 * Post-Binding Configuration for a CDK construct
96 */
97export interface ApiDefinitionConfig {
98 /**
99 * The location of the specification in S3 (mutually exclusive with `inlineDefinition`).
100 *
101 * @default - API definition is not an S3 location
102 */
103 readonly s3Location?: ApiDefinitionS3Location;
104 /**
105 * Inline specification (mutually exclusive with `s3Location`).
106 *
107 * @default - API definition is not defined inline
108 */
109 readonly inlineDefinition?: any;
110}
111/**
112 * OpenAPI specification from an S3 archive.
113 */
114export declare class S3ApiDefinition extends ApiDefinition {
115 private key;
116 private objectVersion?;
117 private bucketName;
118 constructor(bucket: s3.IBucket, key: string, objectVersion?: string | undefined);
119 bind(_scope: Construct): ApiDefinitionConfig;
120}
121/**
122 * OpenAPI specification from an inline JSON object.
123 */
124export declare class InlineApiDefinition extends ApiDefinition {
125 private definition;
126 constructor(definition: any);
127 bind(_scope: Construct): ApiDefinitionConfig;
128}
129/**
130 * OpenAPI specification from a local file.
131 */
132export declare class AssetApiDefinition extends ApiDefinition {
133 private readonly path;
134 private readonly options;
135 private asset?;
136 constructor(path: string, options?: s3_assets.AssetOptions);
137 bind(scope: Construct): ApiDefinitionConfig;
138 bindAfterCreate(scope: Construct, restApi: IRestApi): void;
139}