Module: Scorpio::OpenAPI::V3::Operation

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

Overview

Defined Under Namespace

Modules: Configurables

Instance Attribute Summary

Attributes included from Configurables

#request_media_type, #server, #server_variables

Attributes included from Operation::Configurables

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

Instance Method Summary collapse

Methods included from Configurables

#scheme

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

#request_schema(media_type: self.request_media_type) ⇒ JSI::Schema

Returns:

  • (JSI::Schema)

Raises:

  • (ArgumentError)


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

def request_schema(media_type: self.request_media_type)
  # TODO typechecking on requestBody & children
  request_content = requestBody && requestBody['content']
  return nil unless request_content
  raise(ArgumentError, "please specify media_type for request_schema") unless media_type
  schema = request_content[media_type] && request_content[media_type]['schema']
  return nil unless schema
  JSI::Schema.ensure_schema(schema)
end

#request_schemasJSI::SchemaSet

Returns:

  • (JSI::SchemaSet)


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

def request_schemas
  JSI::SchemaSet.build do |schemas|
    if requestBody && requestBody['content']
      requestBody['content'].each_value do |oa_media_type|
        if oa_media_type['schema']
          schemas << oa_media_type['schema']
        end
      end
    end
  end
end

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

Returns:

  • (JSI::Schema)


295
296
297
298
299
300
301
# File 'lib/scorpio/openapi/operation.rb', line 295

def response_schema(status: , media_type: )
  oa_response = self.oa_response(status: status)
  oa_media_types = oa_response ? oa_response['content'] : nil # Scorpio::OpenAPI::V3::MediaTypes
  oa_media_type = oa_media_types ? oa_media_types[media_type] : nil # Scorpio::OpenAPI::V3::MediaType
  oa_schema = oa_media_type ? oa_media_type['schema'] : nil # Scorpio::OpenAPI::V3::Schema
  oa_schema ? JSI::Schema.ensure_schema(oa_schema) : nil
end

#response_schemasJSI::SchemaSet

Returns:

  • (JSI::SchemaSet)


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

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