Class: AWSCDK::APIGateway::MethodOptions

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key_required: nil, authorization_scopes: nil, authorization_type: nil, authorizer: nil, method_responses: nil, operation_name: nil, request_models: nil, request_parameters: nil, request_validator: nil, request_validator_options: nil) ⇒ MethodOptions

Returns a new instance of MethodOptions.

Parameters:

  • api_key_required (Boolean, nil) (defaults to: nil)

    Indicates whether the method requires clients to submit a valid API key.

  • authorization_scopes (Array<String>, nil) (defaults to: nil)

    A list of authorization scopes configured on the method.

  • authorization_type (AWSCDK::APIGateway::AuthorizationType, nil) (defaults to: nil)

    Method authorization. If the value is set of Custom, an authorizer must also be specified.

  • authorizer (AWSCDK::APIGateway::IAuthorizer, nil) (defaults to: nil)

    If authorizationType is Custom, this specifies the ID of the method authorizer resource.

  • method_responses (Array<AWSCDK::APIGateway::MethodResponse>, nil) (defaults to: nil)

    The responses that can be sent to the client who calls the method.

  • operation_name (String, nil) (defaults to: nil)

    A friendly operation name for the method.

  • request_models (Hash{String => AWSCDK::APIGateway::IModel}, nil) (defaults to: nil)

    The models which describe data structure of request payload.

  • request_parameters (Hash{String => Boolean}, nil) (defaults to: nil)

    The request parameters that API Gateway accepts.

  • request_validator (AWSCDK::APIGateway::IRequestValidator, nil) (defaults to: nil)

    The ID of the associated request validator.

  • request_validator_options (AWSCDK::APIGateway::RequestValidatorOptions, nil) (defaults to: nil)

    Request validator options to create new validator Only one of requestValidator or requestValidatorOptions must be specified.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'api_gateway/method_options.rb', line 16

def initialize(api_key_required: nil, authorization_scopes: nil, authorization_type: nil, authorizer: nil, method_responses: nil, operation_name: nil, request_models: nil, request_parameters: nil, request_validator: nil, request_validator_options: nil)
  @api_key_required = api_key_required
  Jsii::Type.check_type(@api_key_required, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJib29sZWFuIn0=")), "apiKeyRequired") unless @api_key_required.nil?
  @authorization_scopes = authorization_scopes
  Jsii::Type.check_type(@authorization_scopes, JSON.parse(Base64.strict_decode64("eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7InByaW1pdGl2ZSI6InN0cmluZyJ9LCJraW5kIjoiYXJyYXkifX0=")), "authorizationScopes") unless @authorization_scopes.nil?
  @authorization_type = authorization_type
  Jsii::Type.check_type(@authorization_type, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfYXBpZ2F0ZXdheS5BdXRob3JpemF0aW9uVHlwZSJ9")), "authorizationType") unless @authorization_type.nil?
  @authorizer = authorizer
  Jsii::Type.check_type(@authorizer, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfYXBpZ2F0ZXdheS5JQXV0aG9yaXplciJ9")), "authorizer") unless @authorizer.nil?
  @method_responses = method_responses.is_a?(Array) ? method_responses.map { |jsii_v0| jsii_v0.is_a?(Hash) ? ::AWSCDK::APIGateway::MethodResponse.new(**jsii_v0.transform_keys(&:to_sym)) : jsii_v0 } : method_responses
  Jsii::Type.check_type(@method_responses, JSON.parse(Base64.strict_decode64("eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7ImZxbiI6ImF3cy1jZGstbGliLmF3c19hcGlnYXRld2F5Lk1ldGhvZFJlc3BvbnNlIn0sImtpbmQiOiJhcnJheSJ9fQ==")), "methodResponses") unless @method_responses.nil?
  @operation_name = operation_name
  Jsii::Type.check_type(@operation_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "operationName") unless @operation_name.nil?
  @request_models = request_models
  Jsii::Type.check_type(@request_models, JSON.parse(Base64.strict_decode64("eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7ImZxbiI6ImF3cy1jZGstbGliLmF3c19hcGlnYXRld2F5LklNb2RlbCJ9LCJraW5kIjoibWFwIn19")), "requestModels") unless @request_models.nil?
  @request_parameters = request_parameters
  Jsii::Type.check_type(@request_parameters, JSON.parse(Base64.strict_decode64("eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7InByaW1pdGl2ZSI6ImJvb2xlYW4ifSwia2luZCI6Im1hcCJ9fQ==")), "requestParameters") unless @request_parameters.nil?
  @request_validator = request_validator
  Jsii::Type.check_type(@request_validator, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfYXBpZ2F0ZXdheS5JUmVxdWVzdFZhbGlkYXRvciJ9")), "requestValidator") unless @request_validator.nil?
  @request_validator_options = request_validator_options.is_a?(Hash) ? ::AWSCDK::APIGateway::RequestValidatorOptions.new(**request_validator_options.transform_keys(&:to_sym)) : request_validator_options
  Jsii::Type.check_type(@request_validator_options, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfYXBpZ2F0ZXdheS5SZXF1ZXN0VmFsaWRhdG9yT3B0aW9ucyJ9")), "requestValidatorOptions") unless @request_validator_options.nil?
end

Instance Attribute Details

#api_key_requiredBoolean? (readonly)

Note:

Default: false

Indicates whether the method requires clients to submit a valid API key.

Returns:

  • (Boolean, nil)


43
44
45
# File 'api_gateway/method_options.rb', line 43

def api_key_required
  @api_key_required
end

#authorization_scopesArray<String>? (readonly)

Note:

Default: - no authorization scopes

A list of authorization scopes configured on the method.

The scopes are used with a COGNITO_USER_POOLS authorizer to authorize the method invocation.



52
53
54
# File 'api_gateway/method_options.rb', line 52

def authorization_scopes
  @authorization_scopes
end

#authorization_typeAWSCDK::APIGateway::AuthorizationType? (readonly)

Note:

Default: - open access unless authorizer is specified

Method authorization. If the value is set of Custom, an authorizer must also be specified.

If you're using one of the authorizers that are available via the Authorizer class, such as Authorizer#token(), it is recommended that this option not be specified. The authorizer will take care of setting the correct authorization type. However, specifying an authorization type using this property that conflicts with what is expected by the Authorizer will result in an error.



62
63
64
# File 'api_gateway/method_options.rb', line 62

def authorization_type
  @authorization_type
end

#authorizerAWSCDK::APIGateway::IAuthorizer? (readonly)

If authorizationType is Custom, this specifies the ID of the method authorizer resource.

If specified, the value of authorization_type must be set to Custom



68
69
70
# File 'api_gateway/method_options.rb', line 68

def authorizer
  @authorizer
end

#method_responsesArray<AWSCDK::APIGateway::MethodResponse>? (readonly)

Note:

Default: None This property is not required, but if these are not supplied for a Lambda proxy integration, the Lambda function must return a value of the correct format, for the integration response to be correctly mapped to a response to the client.

The responses that can be sent to the client who calls the method.



74
75
76
# File 'api_gateway/method_options.rb', line 74

def method_responses
  @method_responses
end

#operation_nameString? (readonly)

A friendly operation name for the method.

For example, you can assign the OperationName of ListPets for the GET /pets method.

Returns:

  • (String, nil)


81
82
83
# File 'api_gateway/method_options.rb', line 81

def operation_name
  @operation_name
end

#request_modelsHash{String => AWSCDK::APIGateway::IModel}? (readonly)

The models which describe data structure of request payload.

When combined with request_validator or request_validator_options, the service will validate the API request payload before it reaches the API's Integration (including proxies). Specify request_models as key-value pairs, with a content type (e.g. 'application/json') as the key and an API Gateway Model as the value.

Examples:

api = nil # AWSCDK::APIGateway::RestAPI
user_lambda = nil # AWSCDK::Lambda::Function

user_model = api.add_model("UserModel", {
    schema: {
        type: AWSCDK::APIGateway::JsonSchemaType::OBJECT,
        properties: {
            user_id: {
                type: AWSCDK::APIGateway::JsonSchemaType::STRING,
            },
            name: {
                type: AWSCDK::APIGateway::JsonSchemaType::STRING,
            },
        },
        required: ["userId"],
    },
})
api.root.add_resource("user").add_method("POST",
AWSCDK::APIGateway::LambdaIntegration.new(user_lambda), {
    request_models: {
        "application/json" => user_model,
    },
})

Returns:

See Also:



117
118
119
# File 'api_gateway/method_options.rb', line 117

def request_models
  @request_models
end

#request_parametersHash{String => Boolean}? (readonly)

Note:

Default: None

The request parameters that API Gateway accepts.

Specify request parameters as key-value pairs (string-to-Boolean mapping), with a source as the key and a Boolean as the value. The Boolean specifies whether a parameter is required. A source must match the format method.request.location.name, where the location is querystring, path, or header, and name is a valid, unique parameter name.

Returns:

  • (Hash{String => Boolean}, nil)


128
129
130
# File 'api_gateway/method_options.rb', line 128

def request_parameters
  @request_parameters
end

#request_validatorAWSCDK::APIGateway::IRequestValidator? (readonly)

Note:

Default: - No default validator

The ID of the associated request validator.

Only one of request_validator or request_validator_options must be specified. Works together with request_models or request_parameters to validate the request before it reaches integration like Lambda Proxy Integration.



137
138
139
# File 'api_gateway/method_options.rb', line 137

def request_validator
  @request_validator
end

#request_validator_optionsAWSCDK::APIGateway::RequestValidatorOptions? (readonly)

Note:

Default: - No default validator

Request validator options to create new validator Only one of requestValidator or requestValidatorOptions must be specified.

Works together with request_models or request_parameters to validate the request before it reaches integration like Lambda Proxy Integration.



145
146
147
# File 'api_gateway/method_options.rb', line 145

def request_validator_options
  @request_validator_options
end

Class Method Details

.jsii_propertiesObject



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'api_gateway/method_options.rb', line 147

def self.jsii_properties
  {
    :api_key_required => "apiKeyRequired",
    :authorization_scopes => "authorizationScopes",
    :authorization_type => "authorizationType",
    :authorizer => "authorizer",
    :method_responses => "methodResponses",
    :operation_name => "operationName",
    :request_models => "requestModels",
    :request_parameters => "requestParameters",
    :request_validator => "requestValidator",
    :request_validator_options => "requestValidatorOptions",
  }
end

Instance Method Details

#to_jsiiObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'api_gateway/method_options.rb', line 162

def to_jsii
  result = {}
  result.merge!({
    "apiKeyRequired" => @api_key_required,
    "authorizationScopes" => @authorization_scopes,
    "authorizationType" => @authorization_type,
    "authorizer" => @authorizer,
    "methodResponses" => @method_responses,
    "operationName" => @operation_name,
    "requestModels" => @request_models,
    "requestParameters" => @request_parameters,
    "requestValidator" => @request_validator,
    "requestValidatorOptions" => @request_validator_options,
  })
  result.compact
end