Module: Scorpio::OpenAPI::V2::Operation

Includes:
Operation, Configurables
Defined in:
lib/scorpio/openapi.rb,
lib/scorpio/openapi/operation.rb

Defined Under Namespace

Modules: Configurables

Instance Attribute Summary

Attributes included from Configurables

#request_media_type, #scheme

Attributes included from Operation::Configurables

#base_url, #faraday_adapter, #faraday_builder, #logger, #request_headers, #user_agent

Instance Method Summary collapse

Methods included from Configurables

#server, #server_variables

Methods included from Operation

#build_request, #http_method, #human_id, #inferred_parameters, #oa_response, #openapi_document, #path_template, #path_template_str, #request_accessor_module, #run, #run_ur, #uri_template, #v2?, #v3?

Instance Method Details

#body_parameter#to_hash

Returns the body parameter.

Returns:

  • (#to_hash)

    the body parameter

Raises:



269
270
271
272
273
274
275
276
277
278
279
# File 'lib/scorpio/openapi/operation.rb', line 269

def body_parameter
  body_parameters = (parameters || []).select { |parameter| parameter['in'] == 'body' }
  if body_parameters.size == 0
    nil
  elsif body_parameters.size == 1
    body_parameters.first
  else
    # TODO blame
    raise(OpenAPI::SemanticError, "multiple body parameters on operation #{operation.pretty_inspect.chomp}")
  end
end

#request_schema(media_type: nil) ⇒ JSI::Schema

Returns request schema for the given media_type.

Parameters:

  • media_type (defaults to: nil)

    unused

Returns:

  • (JSI::Schema)

    request schema for the given media_type



283
284
285
286
287
288
289
# File 'lib/scorpio/openapi/operation.rb', line 283

def request_schema(media_type: nil)
  if body_parameter && body_parameter['schema']
    JSI::Schema.new(body_parameter['schema'])
  else
    nil
  end
end

#request_schemasArray<JSI::Schema>

Returns:

  • (Array<JSI::Schema>)


292
293
294
# File 'lib/scorpio/openapi/operation.rb', line 292

def request_schemas
  request_schema ? [request_schema] : []
end

#response_schema(status:, media_type: nil) ⇒ JSI::Schema

Parameters:

  • status (Integer, String)

    response status

  • media_type (defaults to: nil)

    unused

Returns:

  • (JSI::Schema)


299
300
301
302
303
# File 'lib/scorpio/openapi/operation.rb', line 299

def response_schema(status: , media_type: nil)
  oa_response = self.oa_response(status: status)
  oa_response_schema = oa_response ? oa_response['schema'] : nil # Scorpio::OpenAPI::V2::Schema
  oa_response_schema ? JSI::Schema.new(oa_response_schema) : nil
end