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

the body parameter

Returns:

  • (#to_hash)

Raises:



306
307
308
309
310
311
312
313
314
315
316
# File 'lib/scorpio/openapi/operation.rb', line 306

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

request schema for the given media_type

Parameters:

  • media_type (defaults to: nil)

    unused

Returns:

  • (JSI::Schema)


321
322
323
324
325
326
327
# File 'lib/scorpio/openapi/operation.rb', line 321

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

#request_schemasJSI::SchemaSet

Returns:

  • (JSI::SchemaSet)


330
331
332
# File 'lib/scorpio/openapi/operation.rb', line 330

def request_schemas
  request_schema ? JSI::SchemaSet[request_schema] : JSI::SchemaSet[]
end

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

Parameters:

  • status (Integer, String)

    response status

  • media_type (defaults to: nil)

    unused

Returns:

  • (JSI::Schema)


337
338
339
340
341
# File 'lib/scorpio/openapi/operation.rb', line 337

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.ensure_schema(oa_response_schema) : nil
end

#response_schemasJSI::SchemaSet

Returns:

  • (JSI::SchemaSet)


344
345
346
347
348
349
350
351
352
353
354
# File 'lib/scorpio/openapi/operation.rb', line 344

def response_schemas
  JSI::SchemaSet.build do |schemas|
    if responses
      responses.each_value do |oa_response|
        if oa_response['schema']
          schemas << oa_response['schema']
        end
      end
    end
  end
end