Class: JSON::Oas::Validator

Inherits:
Validator
  • Object
show all
Defined in:
lib/json-schema-oas/validator.rb

Overview

Validator to validate data against a OpenAPI schema

Class Method Summary collapse

Class Method Details

.compute_fragment(version, opts) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/json-schema-oas/validator.rb', line 23

def compute_fragment(version, opts)
  options = Hash(opts)
  return options if options[:fragment]

  if options[:with_schema]
    options[:fragment] = Fragment.schema_for(version, options[:with_schema].to_s)
  elsif options[:with_response]
    options[:fragment] = Fragment.response_schema_for(version, *Array(options[:with_response]))
  end

  options
end

.valid_schema?(schema, version) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/json-schema-oas/validator.rb', line 11

def valid_schema?(schema, version)
  specs = case version
          when Version::OAS2
            OAS2_SCHEMA_PATH
          when Version::OAS3
            OAS3_SCHEMA_PATH
          else
            raise Error, Error::UNKNOWN_VERSION_ERROR
          end
  JSON::Validator.fully_validate(specs, schema).empty?
end