Skip to content
v2.275.0

InlineApiDefinition Class ​

OpenAPI specification from an inline JSON object.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_apigateway as apigateway } from 'aws-cdk-lib';

declare const definition: any;
const inlineApiDefinition = new apigateway.InlineApiDefinition(definition);
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_apigateway as apigateway

# definition: Any

inline_api_definition = apigateway.InlineApiDefinition(definition)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.apigateway.*;

Object definition;

InlineApiDefinition inlineApiDefinition = new InlineApiDefinition(definition);
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.APIGateway;

var definition;

var inlineApiDefinition = new InlineApiDefinition(definition);
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

var definition interface{}

inlineApiDefinition := awscdk.Aws_apigateway.NewInlineApiDefinition(definition)

Initializer ​

ts
new InlineApiDefinition(definition: any)
python
InlineApiDefinition(definition: Any)
java
new InlineApiDefinition(Object definition)
csharp
new InlineApiDefinition(object definition)
go
NewInlineApiDefinition(Definition interface{})

Methods ​

bind(_scope: Construct): ApiDefinitionConfigdef bind(self, _scope: Construct) -> ApiDefinitionConfigpublic ApiDefinitionConfig bind(Construct _scope)public ApiDefinitionConfig Bind(Construct _scope)func Bind(_scope Construct) ApiDefinitionConfig#
Called when the specification is initialized to allow this object to bind to the stack, add resources and have fun.
bindAfterCreate(_scope: Construct, _restApi: IRestApiRef): voiddef bind_after_create(self, _scope: Construct, _rest_api: IRestApiRef) -> Nonepublic void bindAfterCreate(Construct _scope, IRestApiRef _restApi)public void BindAfterCreate(Construct _scope, IRestApiRef _restApi)func BindAfterCreate(_scope Construct, _restApi IRestApiRef)#
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.

fromAsset(file: string, options?: AssetOptions): AssetApiDefinition@staticmethod def from_asset(file: str, options: typing.Optional[AssetOptions] = None) -> AssetApiDefinitionpublic static AssetApiDefinition fromAsset(String file, AssetOptions options)public static AssetApiDefinition FromAsset(string file, AssetOptions? options = null)func FromAsset(File *string, Options AssetOptions) AssetApiDefinitionstatic#
Loads the API specification from a local disk asset.
fromBucket(bucket: IBucket, key: string, objectVersion?: string): S3ApiDefinition@staticmethod def from_bucket(bucket: IBucket, key: str, object_version: typing.Optional[str] = None) -> S3ApiDefinitionpublic static S3ApiDefinition fromBucket(IBucket bucket, String key, String objectVersion)public static S3ApiDefinition FromBucket(IBucket bucket, string key, string? objectVersion = null)func FromBucket(Bucket IBucket, Key *string, ObjectVersion *string) S3ApiDefinitionstatic#
Creates an API definition from a specification file in an S3 bucket.
fromInline(definition: any): InlineApiDefinition // chainable@staticmethod def from_inline(definition: Any) -> InlineApiDefinitionpublic static InlineApiDefinition fromInline(Object definition)public static InlineApiDefinition FromInline(object definition)func FromInline(Definition interface{}) InlineApiDefinitionstatic#
Create an API definition from an inline object.

The inline object must follow the schema of OpenAPI 2.0 or OpenAPI 3.0

example
ts
  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',
        },
      },
    },
  });