Class: JSONSchemer::OpenAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/json_schemer/openapi.rb

Instance Method Summary collapse

Constructor Details

#initialize(document, **options) ⇒ OpenAPI

Returns a new instance of OpenAPI.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/json_schemer/openapi.rb', line 4

def initialize(document, **options)
  @document = document

  version = document['openapi']
  case version
  when /\A3\.1\.\d+\z/
    @document_schema = JSONSchemer.openapi31_document
    meta_schema = document.fetch('jsonSchemaDialect') { OpenAPI31::BASE_URI.to_s }
  when /\A3\.0\.\d+\z/
    @document_schema = JSONSchemer.openapi30_document
    meta_schema = OpenAPI30::BASE_URI.to_s
  else
    raise UnsupportedOpenAPIVersion, version
  end

  @schema = JSONSchemer.schema(@document, :meta_schema => meta_schema, **options)
end

Instance Method Details

#ref(value) ⇒ Object



30
31
32
# File 'lib/json_schemer/openapi.rb', line 30

def ref(value)
  @schema.ref(value)
end

#schema(name) ⇒ Object



34
35
36
# File 'lib/json_schemer/openapi.rb', line 34

def schema(name)
  ref("#/components/schemas/#{name}")
end

#valid?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/json_schemer/openapi.rb', line 22

def valid?
  @document_schema.valid?(@document)
end

#validate(**options) ⇒ Object



26
27
28
# File 'lib/json_schemer/openapi.rb', line 26

def validate(**options)
  @document_schema.validate(@document, **options)
end