Module: Scorpio::OpenAPI::Document

Includes:
Configurables
Included in:
V2::Document, V3::Document
Defined in:
lib/scorpio/openapi/document.rb

Overview

A document that defines or describes an API. An OpenAPI description document uses and conforms to the OpenAPI Specification.

Scorpio::OpenAPI::Document is a module common to V2 and V3 documents.

Defined Under Namespace

Modules: Configurables

Instance Attribute Summary

Attributes included from Configurables

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_instance(instance) ⇒ Scorpio::OpenAPI::V2::Document, Scorpio::OpenAPI::V3::Document

takes a document, generally a Hash, and returns a Scorpio OpenAPI Document instantiating it.

Parameters:

  • instance (#to_hash)

    the document to represent as a Scorpio OpenAPI Document

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/scorpio/openapi/document.rb', line 16

def from_instance(instance)
  if instance.is_a?(Scorpio::OpenAPI::Document)
    instance
  elsif instance.is_a?(JSI::Base)
    raise(TypeError, "instance is unexpected JSI type: #{instance.class.inspect}")
  elsif instance.respond_to?(:to_hash)
    if instance['swagger'] =~ /\A2(\.|\z)/
      instance = Scorpio::OpenAPI::V2::Document.new_jsi(instance)
    elsif instance['openapi'] =~ /\A3(\.|\z)/
      instance = Scorpio::OpenAPI::V3::Document.new_jsi(instance)
    else
      raise(ArgumentError, "instance does not look like a recognized openapi document")
    end
  else
    raise(TypeError, "instance does not look like a hash (json object)")
  end
end

Instance Method Details

#operationsObject



76
77
78
79
# File 'lib/scorpio/openapi/document.rb', line 76

def operations
  return @operations if instance_variable_defined?(:@operations)
  @operations = OperationsScope.new(self)
end

#v2?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/scorpio/openapi/document.rb', line 68

def v2?
  is_a?(V2::Document)
end

#v3?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/scorpio/openapi/document.rb', line 72

def v3?
  is_a?(V3::Document)
end