Class: JSONSchemer::OpenAPI
- Inherits:
-
Object
- Object
- JSONSchemer::OpenAPI
- Defined in:
- lib/json_schemer/openapi.rb
Instance Method Summary collapse
-
#initialize(document, **options) ⇒ OpenAPI
constructor
A new instance of OpenAPI.
- #ref(value) ⇒ Object
- #schema(name) ⇒ Object
- #valid? ⇒ Boolean
- #validate(**options) ⇒ Object
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, **) @document = document version = document['openapi'] case version when /\A3\.1\.\d+\z/ @document_schema = JSONSchemer.openapi31_document = document.fetch('jsonSchemaDialect') { OpenAPI31::BASE_URI.to_s } when /\A3\.0\.\d+\z/ @document_schema = JSONSchemer.openapi30_document = OpenAPI30::BASE_URI.to_s else raise UnsupportedOpenAPIVersion, version end @schema = JSONSchemer.schema(@document, :meta_schema => , **) 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
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(**) @document_schema.validate(@document, **) end |