Class: AWSCDK::APIGateway::APIDefinition

Inherits:
Jsii::Object
  • Object
show all
Defined in:
api_gateway/api_definition.rb

Overview

Represents an OpenAPI definition asset.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAPIDefinition

Returns a new instance of APIDefinition.



8
9
10
# File 'api_gateway/api_definition.rb', line 8

def initialize
  Jsii::Object.instance_method(:initialize).bind(self).call
end

Class Method Details

.from_asset(file, options = nil) ⇒ AWSCDK::APIGateway::AssetAPIDefinition

Loads the API specification from a local disk asset.

Parameters:

Returns:



24
25
26
27
28
29
# File 'api_gateway/api_definition.rb', line 24

def self.from_asset(file, options = nil)
  Jsii::Type.check_type(file, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "file")
  options = options.is_a?(Hash) ? ::AWSCDK::S3Assets::AssetOptions.new(**options.transform_keys(&:to_sym)) : options
  Jsii::Type.check_type(options, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfczNfYXNzZXRzLkFzc2V0T3B0aW9ucyJ9")), "options") unless options.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_apigateway.ApiDefinition", "fromAsset", [file, options])
end

.from_bucket(bucket, key, object_version = nil) ⇒ AWSCDK::APIGateway::S3APIDefinition

Creates an API definition from a specification file in an S3 bucket.

Parameters:

Returns:



37
38
39
40
41
42
# File 'api_gateway/api_definition.rb', line 37

def self.from_bucket(bucket, key, object_version = nil)
  Jsii::Type.check_type(bucket, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfczMuSUJ1Y2tldCJ9")), "bucket")
  Jsii::Type.check_type(key, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "key")
  Jsii::Type.check_type(object_version, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "objectVersion") unless object_version.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_apigateway.ApiDefinition", "fromBucket", [bucket, key, object_version])
end

.from_inline(definition) ⇒ AWSCDK::APIGateway::InlineAPIDefinition

Create an API definition from an inline object.

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

Examples:

AWSCDK::APIGateway::APIDefinition.from_inline({
    openapi: "3.0.2",
    paths: {
        "/pets" => {
            get: {
                "responses" => {
                    200: {
                        content: {
                            "application/json" => {
                                schema: {
                                    $ref: "#/components/schemas/Empty",
                                },
                            },
                        },
                    },
                },
                "x-amazon-apigateway-integration" => {
                    responses: {
                        default: {
                            status_code: "200",
                        },
                    },
                    request_templates: {
                        "application/json" => "{\"statusCode\": 200}",
                    },
                    passthrough_behavior: "when_no_match",
                    type: "mock",
                },
            },
        },
    },
    components: {
        schemas: {
            Empty: {
                title: "Empty Schema",
                type: "object",
            },
        },
    },
})

Parameters:

  • definition (Object)

Returns:



92
93
94
95
# File 'api_gateway/api_definition.rb', line 92

def self.from_inline(definition)
  Jsii::Type.check_type(definition, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "definition")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_apigateway.ApiDefinition", "fromInline", [definition])
end

.jsii_overridable_methodsObject



12
13
14
15
16
17
# File 'api_gateway/api_definition.rb', line 12

def self.jsii_overridable_methods
  {
    :bind => { kind: :method, name: "bind", is_optional: false },
    :bind_after_create => { kind: :method, name: "bindAfterCreate", is_optional: false },
  }
end

Instance Method Details

#bind(scope) ⇒ AWSCDK::APIGateway::APIDefinitionConfig

Called when the specification is initialized to allow this object to bind to the stack, add resources and have fun.

Parameters:

  • scope (Constructs::Construct)

    The binding scope.

Returns:



101
102
103
104
# File 'api_gateway/api_definition.rb', line 101

def bind(scope)
  Jsii::Type.check_type(scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLkNvbnN0cnVjdCJ9")), "scope")
  jsii_call_method("bind", [scope])
end

#bind_after_create(_scope, _rest_api) ⇒ void

This method returns an undefined value.

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.

Parameters:



114
115
116
117
118
# File 'api_gateway/api_definition.rb', line 114

def bind_after_create(_scope, _rest_api)
  Jsii::Type.check_type(_scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLkNvbnN0cnVjdCJ9")), "_scope")
  Jsii::Type.check_type(_rest_api, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5pbnRlcmZhY2VzLmF3c19hcGlnYXRld2F5LklSZXN0QXBpUmVmIn0=")), "_restApi")
  jsii_call_method("bindAfterCreate", [_scope, _rest_api])
end