class ApiDefinition
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.APIGateway.ApiDefinition |
Java | software.amazon.awscdk.services.apigateway.ApiDefinition |
Python | aws_cdk.aws_apigateway.ApiDefinition |
TypeScript (source) | @aws-cdk/aws-apigateway » ApiDefinition |
Implemented by
Asset
, Inline
, S3
Represents an OpenAPI definition asset.
Example
declare const integration: apigateway.Integration;
const api = new apigateway.SpecRestApi(this, 'books-api', {
apiDefinition: apigateway.ApiDefinition.fromAsset('path-to-file.json')
});
const booksResource = api.root.addResource('books')
booksResource.addMethod('GET', integration);
Initializer
new ApiDefinition()
Methods
Name | Description |
---|---|
bind(scope) | Called when the specification is initialized to allow this object to bind to the stack, add resources and have fun. |
bind | Called after the CFN RestApi resource has been created to allow the Api Definition to bind to it. |
static from | Loads the API specification from a local disk asset. |
static from | Creates an API definition from a specification file in an S3 bucket. |
static from | Create an API definition from an inline object. |
bind(scope)
public bind(scope: Construct): ApiDefinitionConfig
Parameters
- scope
Construct
— The binding scope.
Returns
Called when the specification is initialized to allow this object to bind to the stack, add resources and have fun.
AfterCreate(_scope, _restApi)
bindpublic bindAfterCreate(_scope: Construct, _restApi: IRestApi): void
Parameters
Called after the CFN RestApi resource has been created to allow the Api Definition to bind to it.
Specifically it's required to allow assets to add metadata for tooling like SAM CLI to be able to find their origins.
Asset(file, options?)
static frompublic static fromAsset(file: string, options?: AssetOptions): AssetApiDefinition
Parameters
- file
string
- options
Asset
Options
Returns
Loads the API specification from a local disk asset.
Bucket(bucket, key, objectVersion?)
static frompublic static fromBucket(bucket: IBucket, key: string, objectVersion?: string): S3ApiDefinition
Parameters
- bucket
IBucket
- key
string
- objectVersion
string
Returns
Creates an API definition from a specification file in an S3 bucket.
Inline(definition)
static frompublic static fromInline(definition: any): InlineApiDefinition
Parameters
- definition
any
Returns
Create an API definition from an inline object.
The inline object must follow the schema of OpenAPI 2.0 or OpenAPI 3.0 Example
apigateway.ApiDefinition.fromInline({
openapi: '3.0.2',
paths: {
'/pets': {
get: {
'responses': {
200: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Empty',
},
},
},
},
},
'x-amazon-apigateway-integration': {
responses: {
default: {
statusCode: '200',
},
},
requestTemplates: {
'application/json': '{"statusCode": 200}',
},
passthroughBehavior: 'when_no_match',
type: 'mock',
},
},
},
},
components: {
schemas: {
Empty: {
title: 'Empty Schema',
type: 'object',
},
},
},
});