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, #each_link_page, #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:



352
353
354
355
356
357
358
359
360
361
362
# File 'lib/scorpio/openapi/operation.rb', line 352

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)


367
368
369
370
371
372
373
# File 'lib/scorpio/openapi/operation.rb', line 367

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)


376
377
378
# File 'lib/scorpio/openapi/operation.rb', line 376

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)


383
384
385
386
387
# File 'lib/scorpio/openapi/operation.rb', line 383

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)


390
391
392
393
394
395
396
397
398
399
400
# File 'lib/scorpio/openapi/operation.rb', line 390

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