Module: JSONSchemer
- Defined in:
- lib/json_schemer/errors.rb,
lib/json_schemer.rb,
lib/json_schemer/format.rb,
lib/json_schemer/output.rb,
lib/json_schemer/result.rb,
lib/json_schemer/schema.rb,
lib/json_schemer/content.rb,
lib/json_schemer/keyword.rb,
lib/json_schemer/openapi.rb,
lib/json_schemer/version.rb,
lib/json_schemer/location.rb,
lib/json_schemer/draft4/meta.rb,
lib/json_schemer/draft6/meta.rb,
lib/json_schemer/draft7/meta.rb,
lib/json_schemer/ecma_regexp.rb,
lib/json_schemer/draft4/vocab.rb,
lib/json_schemer/draft6/vocab.rb,
lib/json_schemer/draft7/vocab.rb,
lib/json_schemer/format/email.rb,
lib/json_schemer/configuration.rb,
lib/json_schemer/openapi30/meta.rb,
lib/json_schemer/openapi31/meta.rb,
lib/json_schemer/cached_resolver.rb,
lib/json_schemer/format/duration.rb,
lib/json_schemer/format/hostname.rb,
lib/json_schemer/openapi30/vocab.rb,
lib/json_schemer/openapi31/vocab.rb,
lib/json_schemer/draft201909/meta.rb,
lib/json_schemer/draft202012/meta.rb,
lib/json_schemer/draft201909/vocab.rb,
lib/json_schemer/draft202012/vocab.rb,
lib/json_schemer/openapi30/document.rb,
lib/json_schemer/openapi31/document.rb,
lib/json_schemer/format/json_pointer.rb,
lib/json_schemer/format/uri_template.rb,
lib/json_schemer/openapi30/vocab/base.rb,
lib/json_schemer/openapi31/vocab/base.rb,
lib/json_schemer/draft201909/vocab/core.rb,
lib/json_schemer/draft202012/vocab/core.rb,
lib/json_schemer/draft4/vocab/validation.rb,
lib/json_schemer/draft7/vocab/validation.rb,
lib/json_schemer/draft202012/vocab/content.rb,
lib/json_schemer/draft202012/vocab/meta_data.rb,
lib/json_schemer/draft201909/vocab/applicator.rb,
lib/json_schemer/draft202012/vocab/applicator.rb,
lib/json_schemer/draft202012/vocab/validation.rb,
lib/json_schemer/draft202012/vocab/unevaluated.rb,
lib/json_schemer/draft202012/vocab/format_assertion.rb,
lib/json_schemer/draft202012/vocab/format_annotation.rb
Overview
Defined Under Namespace
Modules: ContentEncoding, ContentMediaType, Draft201909, Draft202012, Draft4, Draft6, Draft7, Errors, Format, Location, OpenAPI30, OpenAPI31, Output
Classes: CachedRefResolver, CachedResolver, Configuration, EcmaRegexp, InvalidEcmaRegexp, InvalidFileURI, InvalidRefPointer, InvalidRefResolution, InvalidRegexpResolution, Keyword, OpenAPI, Result, Schema, UnknownContentEncoding, UnknownContentMediaType, UnknownFormat, UnknownOutputFormat, UnknownRef, UnknownVocabulary, UnsupportedOpenAPIVersion
Constant Summary
collapse
- VOCABULARIES =
{
'https://json-schema.org/draft/2020-12/vocab/core' => Draft202012::Vocab::CORE,
'https://json-schema.org/draft/2020-12/vocab/applicator' => Draft202012::Vocab::APPLICATOR,
'https://json-schema.org/draft/2020-12/vocab/unevaluated' => Draft202012::Vocab::UNEVALUATED,
'https://json-schema.org/draft/2020-12/vocab/validation' => Draft202012::Vocab::VALIDATION,
'https://json-schema.org/draft/2020-12/vocab/format-annotation' => Draft202012::Vocab::FORMAT_ANNOTATION,
'https://json-schema.org/draft/2020-12/vocab/format-assertion' => Draft202012::Vocab::FORMAT_ASSERTION,
'https://json-schema.org/draft/2020-12/vocab/content' => Draft202012::Vocab::CONTENT,
'https://json-schema.org/draft/2020-12/vocab/meta-data' => Draft202012::Vocab::META_DATA,
'https://json-schema.org/draft/2019-09/vocab/core' => Draft201909::Vocab::CORE,
'https://json-schema.org/draft/2019-09/vocab/applicator' => Draft201909::Vocab::APPLICATOR,
'https://json-schema.org/draft/2019-09/vocab/validation' => Draft201909::Vocab::VALIDATION,
'https://json-schema.org/draft/2019-09/vocab/format' => Draft201909::Vocab::FORMAT,
'https://json-schema.org/draft/2019-09/vocab/content' => Draft201909::Vocab::CONTENT,
'https://json-schema.org/draft/2019-09/vocab/meta-data' => Draft201909::Vocab::META_DATA,
'json-schemer://draft7' => Draft7::Vocab::ALL,
'json-schemer://draft6' => Draft6::Vocab::ALL,
'json-schemer://draft4' => Draft4::Vocab::ALL,
'https://spec.openapis.org/oas/3.1/vocab/base' => OpenAPI31::Vocab::BASE,
'json-schemer://openapi30' => OpenAPI30::Vocab::BASE
}
- VOCABULARY_ORDER =
VOCABULARIES.transform_values.with_index { |_vocabulary, index| index }
- WINDOWS_URI_PATH_REGEX =
/\A\/[a-z]:/i
- FILE_URI_REF_RESOLVER =
proc do |uri|
raise InvalidFileURI, 'must use `file` scheme' unless uri.scheme == 'file'
raise InvalidFileURI, 'cannot have a host (use `file:///`)' if uri.host && !uri.host.empty?
path = uri.path
path = path[1..-1] if path.match?(WINDOWS_URI_PATH_REGEX)
JSON.parse(File.read(URI::DEFAULT_PARSER.unescape(path)))
end
- META_SCHEMA_CALLABLES_BY_BASE_URI_STR =
{
Draft202012::BASE_URI.to_s => method(:draft202012),
Draft201909::BASE_URI.to_s => method(:draft201909),
Draft7::BASE_URI.to_s => method(:draft7),
Draft6::BASE_URI.to_s => method(:draft6),
Draft4::BASE_URI.to_s => method(:draft4),
'http://json-schema.org/schema#' => method(:draft4),
OpenAPI31::BASE_URI.to_s => method(:openapi31),
OpenAPI30::BASE_URI.to_s => method(:openapi30)
}.freeze
- META_SCHEMAS_BY_BASE_URI_STR =
Hash.new do |hash, base_uri_str|
next unless META_SCHEMA_CALLABLES_BY_BASE_URI_STR.key?(base_uri_str)
hash[base_uri_str] = META_SCHEMA_CALLABLES_BY_BASE_URI_STR.fetch(base_uri_str).call
end
- CATCHALL =
'*'
- I18N_SEPARATOR =
"\x1F"
- I18N_SCOPE =
'json_schemer'
- I18N_ERRORS_SCOPE =
"#{I18N_SCOPE}#{I18N_SEPARATOR}errors"
- X_ERROR_REGEX =
/%\{(instance|instanceLocation|keywordLocation|absoluteKeywordLocation)\}/
- CLASSIC_ERROR_TYPES =
Hash.new do |hash, klass|
hash[klass] = klass.name.rpartition('::').last.sub(/\A[[:alpha:]]/, &:downcase)
end
- VERSION =
'2.3.0'
Class Method Summary
collapse
Class Method Details
.configuration ⇒ Object
234
235
236
|
# File 'lib/json_schemer.rb', line 234
def configuration
@configuration ||= Configuration.new
end
|
238
239
240
|
# File 'lib/json_schemer.rb', line 238
def configure
yield configuration
end
|
.openapi(document, **options) ⇒ Object
230
231
232
|
# File 'lib/json_schemer.rb', line 230
def openapi(document, **options)
OpenAPI.new(document, **options)
end
|
.openapi30 ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/json_schemer.rb', line 200
def openapi30
@openapi30 ||= Schema.new(
OpenAPI30::SCHEMA,
:vocabulary => {
'json-schemer://draft4' => true,
'json-schemer://openapi30' => true
},
:base_uri => OpenAPI30::BASE_URI,
:formats => OpenAPI30::FORMATS,
:ref_resolver => OpenAPI30::Meta::SCHEMAS.to_proc,
:regexp_resolver => 'ecma'
)
end
|
.openapi30_document ⇒ Object
.openapi31_document ⇒ Object
.schema(schema, **options) ⇒ Object
115
116
117
118
|
# File 'lib/json_schemer.rb', line 115
def schema(schema, **options)
schema = resolve(schema, options)
Schema.new(schema, **options)
end
|
.valid_schema?(schema, **options) ⇒ Boolean
120
121
122
123
|
# File 'lib/json_schemer.rb', line 120
def valid_schema?(schema, **options)
schema = resolve(schema, options)
meta_schema(schema, options).valid?(schema, **options.slice(:output_format, :resolve_enumerators, :access_mode))
end
|
.validate_schema(schema, **options) ⇒ Object
125
126
127
128
|
# File 'lib/json_schemer.rb', line 125
def validate_schema(schema, **options)
schema = resolve(schema, options)
meta_schema(schema, options).validate(schema, **options.slice(:output_format, :resolve_enumerators, :access_mode))
end
|