json_skooma 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +107 -0
- data/data/draft-2019-09/README.md +60 -0
- data/data/draft-2019-09/hyper-schema.json +26 -0
- data/data/draft-2019-09/links.json +91 -0
- data/data/draft-2019-09/meta/applicator.json +56 -0
- data/data/draft-2019-09/meta/content.json +17 -0
- data/data/draft-2019-09/meta/core.json +57 -0
- data/data/draft-2019-09/meta/format.json +14 -0
- data/data/draft-2019-09/meta/hyper-schema.json +29 -0
- data/data/draft-2019-09/meta/meta-data.json +37 -0
- data/data/draft-2019-09/meta/validation.json +98 -0
- data/data/draft-2019-09/output/hyper-schema.json +62 -0
- data/data/draft-2019-09/output/schema.json +86 -0
- data/data/draft-2019-09/output/verbose-example.json +130 -0
- data/data/draft-2019-09/schema.json +42 -0
- data/data/draft-2020-12/README.md +89 -0
- data/data/draft-2020-12/adr/README.md +15 -0
- data/data/draft-2020-12/archive/hyper-schema.json +28 -0
- data/data/draft-2020-12/archive/links.json +93 -0
- data/data/draft-2020-12/archive/meta/hyper-schema.json +30 -0
- data/data/draft-2020-12/hyper-schema.json +27 -0
- data/data/draft-2020-12/links.json +85 -0
- data/data/draft-2020-12/meta/applicator.json +48 -0
- data/data/draft-2020-12/meta/content.json +17 -0
- data/data/draft-2020-12/meta/core.json +51 -0
- data/data/draft-2020-12/meta/format-annotation.json +14 -0
- data/data/draft-2020-12/meta/format-assertion.json +14 -0
- data/data/draft-2020-12/meta/hyper-schema.json +29 -0
- data/data/draft-2020-12/meta/meta-data.json +37 -0
- data/data/draft-2020-12/meta/unevaluated.json +15 -0
- data/data/draft-2020-12/meta/validation.json +98 -0
- data/data/draft-2020-12/output/hyper-schema.json +62 -0
- data/data/draft-2020-12/output/schema.json +96 -0
- data/data/draft-2020-12/output/verbose-example.json +130 -0
- data/data/draft-2020-12/schema.json +58 -0
- data/lib/json_skooma/dialects/draft201909.rb +137 -0
- data/lib/json_skooma/dialects/draft202012.rb +146 -0
- data/lib/json_skooma/formatters.rb +135 -0
- data/lib/json_skooma/inflector.rb +13 -0
- data/lib/json_skooma/json_node.rb +100 -0
- data/lib/json_skooma/json_pointer.rb +79 -0
- data/lib/json_skooma/json_schema.rb +176 -0
- data/lib/json_skooma/keywords/applicator/additional_properties.rb +37 -0
- data/lib/json_skooma/keywords/applicator/all_of.rb +25 -0
- data/lib/json_skooma/keywords/applicator/any_of.rb +26 -0
- data/lib/json_skooma/keywords/applicator/contains.rb +31 -0
- data/lib/json_skooma/keywords/applicator/dependent_schemas.rb +35 -0
- data/lib/json_skooma/keywords/applicator/else.rb +22 -0
- data/lib/json_skooma/keywords/applicator/if.rb +17 -0
- data/lib/json_skooma/keywords/applicator/items.rb +36 -0
- data/lib/json_skooma/keywords/applicator/not.rb +19 -0
- data/lib/json_skooma/keywords/applicator/one_of.rb +35 -0
- data/lib/json_skooma/keywords/applicator/pattern_properties.rb +46 -0
- data/lib/json_skooma/keywords/applicator/prefix_items.rb +31 -0
- data/lib/json_skooma/keywords/applicator/properties.rb +34 -0
- data/lib/json_skooma/keywords/applicator/property_names.rb +25 -0
- data/lib/json_skooma/keywords/applicator/then.rb +22 -0
- data/lib/json_skooma/keywords/base.rb +74 -0
- data/lib/json_skooma/keywords/base_annotation.rb +12 -0
- data/lib/json_skooma/keywords/content/content_encoding.rb +12 -0
- data/lib/json_skooma/keywords/content/content_media_type.rb +12 -0
- data/lib/json_skooma/keywords/content/content_schema.rb +19 -0
- data/lib/json_skooma/keywords/core/anchor.rb +22 -0
- data/lib/json_skooma/keywords/core/comment.rb +12 -0
- data/lib/json_skooma/keywords/core/defs.rb +13 -0
- data/lib/json_skooma/keywords/core/dynamic_anchor.rb +22 -0
- data/lib/json_skooma/keywords/core/dynamic_ref.rb +67 -0
- data/lib/json_skooma/keywords/core/id.rb +28 -0
- data/lib/json_skooma/keywords/core/ref.rb +35 -0
- data/lib/json_skooma/keywords/core/schema.rb +26 -0
- data/lib/json_skooma/keywords/core/vocabulary.rb +34 -0
- data/lib/json_skooma/keywords/draft_2019_09/additional_items.rb +40 -0
- data/lib/json_skooma/keywords/draft_2019_09/items.rb +41 -0
- data/lib/json_skooma/keywords/draft_2019_09/recursive_anchor.rb +12 -0
- data/lib/json_skooma/keywords/draft_2019_09/recursive_ref.rb +46 -0
- data/lib/json_skooma/keywords/draft_2019_09/unevaluated_items.rb +56 -0
- data/lib/json_skooma/keywords/format_annotation/format.rb +27 -0
- data/lib/json_skooma/keywords/meta_data/default.rb +11 -0
- data/lib/json_skooma/keywords/meta_data/deprecated.rb +11 -0
- data/lib/json_skooma/keywords/meta_data/description.rb +11 -0
- data/lib/json_skooma/keywords/meta_data/examples.rb +11 -0
- data/lib/json_skooma/keywords/meta_data/read_only.rb +11 -0
- data/lib/json_skooma/keywords/meta_data/title.rb +11 -0
- data/lib/json_skooma/keywords/meta_data/write_only.rb +11 -0
- data/lib/json_skooma/keywords/unevaluated/unevaluated_items.rb +59 -0
- data/lib/json_skooma/keywords/unevaluated/unevaluated_properties.rb +43 -0
- data/lib/json_skooma/keywords/unknown.rb +21 -0
- data/lib/json_skooma/keywords/validation/const.rb +17 -0
- data/lib/json_skooma/keywords/validation/dependent_required.rb +24 -0
- data/lib/json_skooma/keywords/validation/enum.rb +19 -0
- data/lib/json_skooma/keywords/validation/exclusive_maximum.rb +18 -0
- data/lib/json_skooma/keywords/validation/exclusive_minimum.rb +18 -0
- data/lib/json_skooma/keywords/validation/max_contains.rb +24 -0
- data/lib/json_skooma/keywords/validation/max_items.rb +18 -0
- data/lib/json_skooma/keywords/validation/max_length.rb +18 -0
- data/lib/json_skooma/keywords/validation/max_properties.rb +18 -0
- data/lib/json_skooma/keywords/validation/maximum.rb +18 -0
- data/lib/json_skooma/keywords/validation/min_contains.rb +31 -0
- data/lib/json_skooma/keywords/validation/min_items.rb +18 -0
- data/lib/json_skooma/keywords/validation/min_length.rb +18 -0
- data/lib/json_skooma/keywords/validation/min_properties.rb +18 -0
- data/lib/json_skooma/keywords/validation/minimum.rb +18 -0
- data/lib/json_skooma/keywords/validation/multiple_of.rb +20 -0
- data/lib/json_skooma/keywords/validation/pattern.rb +23 -0
- data/lib/json_skooma/keywords/validation/required.rb +19 -0
- data/lib/json_skooma/keywords/validation/type.rb +26 -0
- data/lib/json_skooma/keywords/validation/unique_items.rb +20 -0
- data/lib/json_skooma/keywords/value_schemas.rb +87 -0
- data/lib/json_skooma/memoizable.rb +21 -0
- data/lib/json_skooma/metaschema.rb +32 -0
- data/lib/json_skooma/registry.rb +130 -0
- data/lib/json_skooma/result.rb +125 -0
- data/lib/json_skooma/sources.rb +55 -0
- data/lib/json_skooma/validators/base.rb +31 -0
- data/lib/json_skooma/validators/date.rb +18 -0
- data/lib/json_skooma/validators/date_time.rb +24 -0
- data/lib/json_skooma/validators/duration.rb +25 -0
- data/lib/json_skooma/validators/email.rb +36 -0
- data/lib/json_skooma/validators/hostname.rb +17 -0
- data/lib/json_skooma/validators/idn_email.rb +30 -0
- data/lib/json_skooma/validators/idn_hostname.rb +15 -0
- data/lib/json_skooma/validators/ipv4.rb +20 -0
- data/lib/json_skooma/validators/ipv6.rb +16 -0
- data/lib/json_skooma/validators/iri.rb +47 -0
- data/lib/json_skooma/validators/iri_reference.rb +15 -0
- data/lib/json_skooma/validators/json_pointer.rb +19 -0
- data/lib/json_skooma/validators/regex.rb +15 -0
- data/lib/json_skooma/validators/relative_json_pointer.rb +18 -0
- data/lib/json_skooma/validators/time.rb +32 -0
- data/lib/json_skooma/validators/uri.rb +60 -0
- data/lib/json_skooma/validators/uri_reference.rb +15 -0
- data/lib/json_skooma/validators/uri_template.rb +26 -0
- data/lib/json_skooma/validators/uuid.rb +15 -0
- data/lib/json_skooma/validators.rb +17 -0
- data/lib/json_skooma/version.rb +5 -0
- data/lib/json_skooma/vocabulary.rb +12 -0
- data/lib/json_skooma.rb +39 -0
- metadata +244 -0
@@ -0,0 +1,130 @@
|
|
1
|
+
{
|
2
|
+
"valid": false,
|
3
|
+
"keywordLocation": "",
|
4
|
+
"instanceLocation": "",
|
5
|
+
"errors": [
|
6
|
+
{
|
7
|
+
"valid": true,
|
8
|
+
"keywordLocation": "/$defs",
|
9
|
+
"instanceLocation": ""
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"valid": true,
|
13
|
+
"keywordLocation": "/type",
|
14
|
+
"instanceLocation": ""
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"valid": false,
|
18
|
+
"keywordLocation": "/items",
|
19
|
+
"instanceLocation": "",
|
20
|
+
"errors": [
|
21
|
+
{
|
22
|
+
"valid": true,
|
23
|
+
"keywordLocation": "/items/$ref",
|
24
|
+
"absoluteKeywordLocation":
|
25
|
+
"https://example.com/polygon#/items/$ref",
|
26
|
+
"instanceLocation": "/0",
|
27
|
+
"annotations": [
|
28
|
+
{
|
29
|
+
"valid": true,
|
30
|
+
"keywordLocation": "/items/$ref",
|
31
|
+
"absoluteKeywordLocation":
|
32
|
+
"https://example.com/polygon#/$defs/point",
|
33
|
+
"instanceLocation": "/0",
|
34
|
+
"annotations": [
|
35
|
+
{
|
36
|
+
"valid": true,
|
37
|
+
"keywordLocation": "/items/$ref/type",
|
38
|
+
"absoluteKeywordLocation":
|
39
|
+
"https://example.com/polygon#/$defs/point/type",
|
40
|
+
"instanceLocation": "/0"
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"valid": true,
|
44
|
+
"keywordLocation": "/items/$ref/properties",
|
45
|
+
"absoluteKeywordLocation":
|
46
|
+
"https://example.com/polygon#/$defs/point/properties",
|
47
|
+
"instanceLocation": "/0"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"valid": true,
|
51
|
+
"keywordLocation": "/items/$ref/required",
|
52
|
+
"absoluteKeywordLocation":
|
53
|
+
"https://example.com/polygon#/$defs/point/required",
|
54
|
+
"instanceLocation": "/0"
|
55
|
+
},
|
56
|
+
{
|
57
|
+
"valid": true,
|
58
|
+
"keywordLocation": "/items/$ref/additionalProperties",
|
59
|
+
"absoluteKeywordLocation":
|
60
|
+
"https://example.com/polygon#/$defs/point/additionalProperties",
|
61
|
+
"instanceLocation": "/0"
|
62
|
+
}
|
63
|
+
]
|
64
|
+
}
|
65
|
+
]
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"valid": false,
|
69
|
+
"keywordLocation": "/items/$ref",
|
70
|
+
"absoluteKeywordLocation":
|
71
|
+
"https://example.com/polygon#/items/$ref",
|
72
|
+
"instanceLocation": "/1",
|
73
|
+
"errors": [
|
74
|
+
{
|
75
|
+
"valid": false,
|
76
|
+
"keywordLocation": "/items/$ref",
|
77
|
+
"absoluteKeywordLocation":
|
78
|
+
"https://example.com/polygon#/$defs/point",
|
79
|
+
"instanceLocation": "/1",
|
80
|
+
"errors": [
|
81
|
+
{
|
82
|
+
"valid": true,
|
83
|
+
"keywordLocation": "/items/$ref/type",
|
84
|
+
"absoluteKeywordLocation":
|
85
|
+
"https://example.com/polygon#/$defs/point/type",
|
86
|
+
"instanceLocation": "/1"
|
87
|
+
},
|
88
|
+
{
|
89
|
+
"valid": true,
|
90
|
+
"keywordLocation": "/items/$ref/properties",
|
91
|
+
"absoluteKeywordLocation":
|
92
|
+
"https://example.com/polygon#/$defs/point/properties",
|
93
|
+
"instanceLocation": "/1"
|
94
|
+
},
|
95
|
+
{
|
96
|
+
"valid": false,
|
97
|
+
"keywordLocation": "/items/$ref/required",
|
98
|
+
"absoluteKeywordLocation":
|
99
|
+
"https://example.com/polygon#/$defs/point/required",
|
100
|
+
"instanceLocation": "/1"
|
101
|
+
},
|
102
|
+
{
|
103
|
+
"valid": false,
|
104
|
+
"keywordLocation": "/items/$ref/additionalProperties",
|
105
|
+
"absoluteKeywordLocation":
|
106
|
+
"https://example.com/polygon#/$defs/point/additionalProperties",
|
107
|
+
"instanceLocation": "/1",
|
108
|
+
"errors": [
|
109
|
+
{
|
110
|
+
"valid": false,
|
111
|
+
"keywordLocation": "/items/$ref/additionalProperties",
|
112
|
+
"absoluteKeywordLocation":
|
113
|
+
"https://example.com/polygon#/$defs/point/additionalProperties",
|
114
|
+
"instanceLocation": "/1/z"
|
115
|
+
}
|
116
|
+
]
|
117
|
+
}
|
118
|
+
]
|
119
|
+
}
|
120
|
+
]
|
121
|
+
}
|
122
|
+
]
|
123
|
+
},
|
124
|
+
{
|
125
|
+
"valid": false,
|
126
|
+
"keywordLocation": "/minItems",
|
127
|
+
"instanceLocation": ""
|
128
|
+
}
|
129
|
+
]
|
130
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
3
|
+
"$id": "https://json-schema.org/draft/2020-12/schema",
|
4
|
+
"$vocabulary": {
|
5
|
+
"https://json-schema.org/draft/2020-12/vocab/core": true,
|
6
|
+
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
|
7
|
+
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
|
8
|
+
"https://json-schema.org/draft/2020-12/vocab/validation": true,
|
9
|
+
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
|
10
|
+
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
|
11
|
+
"https://json-schema.org/draft/2020-12/vocab/content": true
|
12
|
+
},
|
13
|
+
"$dynamicAnchor": "meta",
|
14
|
+
|
15
|
+
"title": "Core and Validation specifications meta-schema",
|
16
|
+
"allOf": [
|
17
|
+
{"$ref": "meta/core"},
|
18
|
+
{"$ref": "meta/applicator"},
|
19
|
+
{"$ref": "meta/unevaluated"},
|
20
|
+
{"$ref": "meta/validation"},
|
21
|
+
{"$ref": "meta/meta-data"},
|
22
|
+
{"$ref": "meta/format-annotation"},
|
23
|
+
{"$ref": "meta/content"}
|
24
|
+
],
|
25
|
+
"type": ["object", "boolean"],
|
26
|
+
"$comment": "This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",
|
27
|
+
"properties": {
|
28
|
+
"definitions": {
|
29
|
+
"$comment": "\"definitions\" has been replaced by \"$defs\".",
|
30
|
+
"type": "object",
|
31
|
+
"additionalProperties": { "$dynamicRef": "#meta" },
|
32
|
+
"deprecated": true,
|
33
|
+
"default": {}
|
34
|
+
},
|
35
|
+
"dependencies": {
|
36
|
+
"$comment": "\"dependencies\" has been split and replaced by \"dependentSchemas\" and \"dependentRequired\" in order to serve their differing semantics.",
|
37
|
+
"type": "object",
|
38
|
+
"additionalProperties": {
|
39
|
+
"anyOf": [
|
40
|
+
{ "$dynamicRef": "#meta" },
|
41
|
+
{ "$ref": "meta/validation#/$defs/stringArray" }
|
42
|
+
]
|
43
|
+
},
|
44
|
+
"deprecated": true,
|
45
|
+
"default": {}
|
46
|
+
},
|
47
|
+
"$recursiveAnchor": {
|
48
|
+
"$comment": "\"$recursiveAnchor\" has been replaced by \"$dynamicAnchor\".",
|
49
|
+
"$ref": "meta/core#/$defs/anchorString",
|
50
|
+
"deprecated": true
|
51
|
+
},
|
52
|
+
"$recursiveRef": {
|
53
|
+
"$comment": "\"$recursiveRef\" has been replaced by \"$dynamicRef\".",
|
54
|
+
"$ref": "meta/core#/$defs/uriReferenceString",
|
55
|
+
"deprecated": true
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSONSkooma
|
4
|
+
module Dialects
|
5
|
+
module Draft201909
|
6
|
+
class << self
|
7
|
+
def call(registry, assert_formats: false)
|
8
|
+
registry.add_source(
|
9
|
+
"https://json-schema.org/draft/2019-09/",
|
10
|
+
Sources::Local.new(File.join(DATA_DIR, "draft-2019-09").to_s, suffix: ".json")
|
11
|
+
)
|
12
|
+
|
13
|
+
registry.add_vocabulary(
|
14
|
+
"https://json-schema.org/draft/2019-09/vocab/core",
|
15
|
+
Keywords::Core::Schema,
|
16
|
+
Keywords::Core::Vocabulary,
|
17
|
+
Keywords::Core::Id,
|
18
|
+
Keywords::Core::Ref,
|
19
|
+
Keywords::Core::Anchor,
|
20
|
+
Keywords::Draft201909::RecursiveRef,
|
21
|
+
Keywords::Draft201909::RecursiveAnchor,
|
22
|
+
Keywords::Core::Defs,
|
23
|
+
Keywords::Core::Comment
|
24
|
+
)
|
25
|
+
|
26
|
+
registry.add_vocabulary(
|
27
|
+
"https://json-schema.org/draft/2019-09/vocab/applicator",
|
28
|
+
Keywords::Applicator::AllOf,
|
29
|
+
Keywords::Applicator::AnyOf,
|
30
|
+
Keywords::Applicator::OneOf,
|
31
|
+
Keywords::Applicator::Not,
|
32
|
+
Keywords::Applicator::If,
|
33
|
+
Keywords::Applicator::Then,
|
34
|
+
Keywords::Applicator::Else,
|
35
|
+
Keywords::Applicator::DependentSchemas,
|
36
|
+
Keywords::Draft201909::Items,
|
37
|
+
Keywords::Draft201909::AdditionalItems,
|
38
|
+
Keywords::Draft201909::UnevaluatedItems,
|
39
|
+
Keywords::Applicator::Contains,
|
40
|
+
Keywords::Applicator::Properties,
|
41
|
+
Keywords::Applicator::PatternProperties,
|
42
|
+
Keywords::Applicator::AdditionalProperties,
|
43
|
+
Keywords::Unevaluated::UnevaluatedProperties,
|
44
|
+
Keywords::Applicator::PropertyNames
|
45
|
+
)
|
46
|
+
|
47
|
+
registry.add_vocabulary(
|
48
|
+
"https://json-schema.org/draft/2019-09/vocab/validation",
|
49
|
+
Keywords::Validation::Type,
|
50
|
+
Keywords::Validation::Enum,
|
51
|
+
Keywords::Validation::Const,
|
52
|
+
Keywords::Validation::MultipleOf,
|
53
|
+
Keywords::Validation::Maximum,
|
54
|
+
Keywords::Validation::ExclusiveMaximum,
|
55
|
+
Keywords::Validation::Minimum,
|
56
|
+
Keywords::Validation::ExclusiveMinimum,
|
57
|
+
Keywords::Validation::MaxLength,
|
58
|
+
Keywords::Validation::MinLength,
|
59
|
+
Keywords::Validation::Pattern,
|
60
|
+
Keywords::Validation::MaxItems,
|
61
|
+
Keywords::Validation::MinItems,
|
62
|
+
Keywords::Validation::UniqueItems,
|
63
|
+
Keywords::Validation::MaxContains,
|
64
|
+
Keywords::Validation::MinContains,
|
65
|
+
Keywords::Validation::MaxProperties,
|
66
|
+
Keywords::Validation::MinProperties,
|
67
|
+
Keywords::Validation::Required,
|
68
|
+
Keywords::Validation::DependentRequired
|
69
|
+
)
|
70
|
+
|
71
|
+
registry.add_vocabulary(
|
72
|
+
"https://json-schema.org/draft/2019-09/vocab/format",
|
73
|
+
# todo: move to legacy
|
74
|
+
Keywords::FormatAnnotation::Format
|
75
|
+
)
|
76
|
+
|
77
|
+
registry.add_vocabulary(
|
78
|
+
"https://json-schema.org/draft/2019-09/vocab/meta-data",
|
79
|
+
Keywords::MetaData::Title,
|
80
|
+
Keywords::MetaData::Description,
|
81
|
+
Keywords::MetaData::Default,
|
82
|
+
Keywords::MetaData::Deprecated,
|
83
|
+
Keywords::MetaData::ReadOnly,
|
84
|
+
Keywords::MetaData::WriteOnly,
|
85
|
+
Keywords::MetaData::Examples
|
86
|
+
)
|
87
|
+
|
88
|
+
registry.add_vocabulary(
|
89
|
+
"https://json-schema.org/draft/2019-09/vocab/content",
|
90
|
+
Keywords::Content::ContentMediaType,
|
91
|
+
Keywords::Content::ContentEncoding,
|
92
|
+
Keywords::Content::ContentSchema
|
93
|
+
)
|
94
|
+
|
95
|
+
registry.add_metaschema(
|
96
|
+
"https://json-schema.org/draft/2019-09/schema",
|
97
|
+
"https://json-schema.org/draft/2019-09/vocab/core",
|
98
|
+
"https://json-schema.org/draft/2019-09/vocab/applicator",
|
99
|
+
"https://json-schema.org/draft/2019-09/vocab/validation",
|
100
|
+
"https://json-schema.org/draft/2019-09/vocab/format",
|
101
|
+
"https://json-schema.org/draft/2019-09/vocab/meta-data",
|
102
|
+
"https://json-schema.org/draft/2019-09/vocab/content"
|
103
|
+
)
|
104
|
+
|
105
|
+
if assert_formats
|
106
|
+
registry.add_format("date-time", Validators::DateTime)
|
107
|
+
registry.add_format("date", Validators::Date)
|
108
|
+
registry.add_format("time", Validators::Time)
|
109
|
+
registry.add_format("duration", Validators::Duration)
|
110
|
+
|
111
|
+
registry.add_format("email", Validators::Email)
|
112
|
+
registry.add_format("idn-email", Validators::IdnEmail)
|
113
|
+
|
114
|
+
registry.add_format("hostname", Validators::Hostname)
|
115
|
+
registry.add_format("idn-hostname", Validators::IdnHostname)
|
116
|
+
|
117
|
+
registry.add_format("ipv4", Validators::Ipv4)
|
118
|
+
registry.add_format("ipv6", Validators::Ipv6)
|
119
|
+
|
120
|
+
registry.add_format("uri", Validators::Uri)
|
121
|
+
registry.add_format("uri-reference", Validators::UriReference)
|
122
|
+
registry.add_format("iri", Validators::Iri)
|
123
|
+
registry.add_format("iri-reference", Validators::IriReference)
|
124
|
+
registry.add_format("uuid", Validators::Uuid)
|
125
|
+
|
126
|
+
registry.add_format("uri-template", Validators::UriTemplate)
|
127
|
+
|
128
|
+
registry.add_format("json-pointer", Validators::JSONPointer)
|
129
|
+
registry.add_format("relative-json-pointer", Validators::RelativeJSONPointer)
|
130
|
+
|
131
|
+
registry.add_format("regex", Validators::Regex)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSONSkooma
|
4
|
+
module Dialects
|
5
|
+
module Draft202012
|
6
|
+
class << self
|
7
|
+
def call(registry, assert_formats: false)
|
8
|
+
registry.add_source(
|
9
|
+
"https://json-schema.org/draft/2020-12/",
|
10
|
+
Sources::Local.new(File.join(DATA_DIR, "draft-2020-12").to_s, suffix: ".json")
|
11
|
+
)
|
12
|
+
|
13
|
+
registry.add_vocabulary(
|
14
|
+
"https://json-schema.org/draft/2020-12/vocab/core",
|
15
|
+
Keywords::Core::Schema,
|
16
|
+
Keywords::Core::Vocabulary,
|
17
|
+
Keywords::Core::Id,
|
18
|
+
Keywords::Core::Ref,
|
19
|
+
Keywords::Core::Anchor,
|
20
|
+
Keywords::Core::DynamicRef,
|
21
|
+
Keywords::Core::DynamicAnchor,
|
22
|
+
Keywords::Core::Defs,
|
23
|
+
Keywords::Core::Comment
|
24
|
+
)
|
25
|
+
|
26
|
+
registry.add_vocabulary(
|
27
|
+
"https://json-schema.org/draft/2020-12/vocab/applicator",
|
28
|
+
Keywords::Applicator::AllOf,
|
29
|
+
Keywords::Applicator::AnyOf,
|
30
|
+
Keywords::Applicator::OneOf,
|
31
|
+
Keywords::Applicator::Not,
|
32
|
+
Keywords::Applicator::If,
|
33
|
+
Keywords::Applicator::Then,
|
34
|
+
Keywords::Applicator::Else,
|
35
|
+
Keywords::Applicator::DependentSchemas,
|
36
|
+
Keywords::Applicator::PrefixItems,
|
37
|
+
Keywords::Applicator::Items,
|
38
|
+
Keywords::Applicator::Contains,
|
39
|
+
Keywords::Applicator::Properties,
|
40
|
+
Keywords::Applicator::PatternProperties,
|
41
|
+
Keywords::Applicator::AdditionalProperties,
|
42
|
+
Keywords::Applicator::PropertyNames
|
43
|
+
)
|
44
|
+
|
45
|
+
registry.add_vocabulary(
|
46
|
+
"https://json-schema.org/draft/2020-12/vocab/unevaluated",
|
47
|
+
Keywords::Unevaluated::UnevaluatedItems,
|
48
|
+
Keywords::Unevaluated::UnevaluatedProperties
|
49
|
+
)
|
50
|
+
|
51
|
+
registry.add_vocabulary(
|
52
|
+
"https://json-schema.org/draft/2020-12/vocab/validation",
|
53
|
+
Keywords::Validation::Type,
|
54
|
+
Keywords::Validation::Enum,
|
55
|
+
Keywords::Validation::Const,
|
56
|
+
Keywords::Validation::MultipleOf,
|
57
|
+
Keywords::Validation::Maximum,
|
58
|
+
Keywords::Validation::ExclusiveMaximum,
|
59
|
+
Keywords::Validation::Minimum,
|
60
|
+
Keywords::Validation::ExclusiveMinimum,
|
61
|
+
Keywords::Validation::MaxLength,
|
62
|
+
Keywords::Validation::MinLength,
|
63
|
+
Keywords::Validation::Pattern,
|
64
|
+
Keywords::Validation::MaxItems,
|
65
|
+
Keywords::Validation::MinItems,
|
66
|
+
Keywords::Validation::UniqueItems,
|
67
|
+
Keywords::Validation::MaxContains,
|
68
|
+
Keywords::Validation::MinContains,
|
69
|
+
Keywords::Validation::MaxProperties,
|
70
|
+
Keywords::Validation::MinProperties,
|
71
|
+
Keywords::Validation::Required,
|
72
|
+
Keywords::Validation::DependentRequired
|
73
|
+
)
|
74
|
+
|
75
|
+
registry.add_vocabulary(
|
76
|
+
"https://json-schema.org/draft/2020-12/vocab/format-annotation",
|
77
|
+
Keywords::FormatAnnotation::Format
|
78
|
+
)
|
79
|
+
|
80
|
+
registry.add_vocabulary(
|
81
|
+
"https://json-schema.org/draft/2020-12/vocab/format-assertion",
|
82
|
+
Keywords::FormatAnnotation::Format
|
83
|
+
)
|
84
|
+
|
85
|
+
registry.add_vocabulary(
|
86
|
+
"https://json-schema.org/draft/2020-12/vocab/meta-data",
|
87
|
+
Keywords::MetaData::Title,
|
88
|
+
Keywords::MetaData::Description,
|
89
|
+
Keywords::MetaData::Default,
|
90
|
+
Keywords::MetaData::Deprecated,
|
91
|
+
Keywords::MetaData::ReadOnly,
|
92
|
+
Keywords::MetaData::WriteOnly,
|
93
|
+
Keywords::MetaData::Examples
|
94
|
+
)
|
95
|
+
|
96
|
+
registry.add_vocabulary(
|
97
|
+
"https://json-schema.org/draft/2020-12/vocab/content",
|
98
|
+
Keywords::Content::ContentMediaType,
|
99
|
+
Keywords::Content::ContentEncoding,
|
100
|
+
Keywords::Content::ContentSchema
|
101
|
+
)
|
102
|
+
|
103
|
+
registry.add_metaschema(
|
104
|
+
"https://json-schema.org/draft/2020-12/schema",
|
105
|
+
"https://json-schema.org/draft/2020-12/vocab/core",
|
106
|
+
"https://json-schema.org/draft/2020-12/vocab/applicator",
|
107
|
+
"https://json-schema.org/draft/2020-12/vocab/unevaluated",
|
108
|
+
"https://json-schema.org/draft/2020-12/vocab/validation",
|
109
|
+
"https://json-schema.org/draft/2020-12/vocab/format-annotation",
|
110
|
+
"https://json-schema.org/draft/2020-12/vocab/meta-data",
|
111
|
+
"https://json-schema.org/draft/2020-12/vocab/content"
|
112
|
+
)
|
113
|
+
|
114
|
+
if assert_formats
|
115
|
+
registry.add_format("date-time", Validators::DateTime)
|
116
|
+
registry.add_format("date", Validators::Date)
|
117
|
+
registry.add_format("time", Validators::Time)
|
118
|
+
registry.add_format("duration", Validators::Duration)
|
119
|
+
|
120
|
+
registry.add_format("email", Validators::Email)
|
121
|
+
registry.add_format("idn-email", Validators::IdnEmail)
|
122
|
+
|
123
|
+
registry.add_format("hostname", Validators::Hostname)
|
124
|
+
registry.add_format("idn-hostname", Validators::IdnHostname)
|
125
|
+
|
126
|
+
registry.add_format("ipv4", Validators::Ipv4)
|
127
|
+
registry.add_format("ipv6", Validators::Ipv6)
|
128
|
+
|
129
|
+
registry.add_format("uri", Validators::Uri)
|
130
|
+
registry.add_format("uri-reference", Validators::UriReference)
|
131
|
+
registry.add_format("iri", Validators::Iri)
|
132
|
+
registry.add_format("iri-reference", Validators::IriReference)
|
133
|
+
registry.add_format("uuid", Validators::Uuid)
|
134
|
+
|
135
|
+
registry.add_format("uri-template", Validators::UriTemplate)
|
136
|
+
|
137
|
+
registry.add_format("json-pointer", Validators::JSONPointer)
|
138
|
+
registry.add_format("relative-json-pointer", Validators::RelativeJSONPointer)
|
139
|
+
|
140
|
+
registry.add_format("regex", Validators::Regex)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSONSkooma
|
4
|
+
module Formatters
|
5
|
+
class << self
|
6
|
+
attr_accessor :formatters
|
7
|
+
|
8
|
+
def [](name)
|
9
|
+
formatters.fetch(name)
|
10
|
+
end
|
11
|
+
|
12
|
+
def register(name, formatter)
|
13
|
+
formatters[name] = formatter
|
14
|
+
end
|
15
|
+
end
|
16
|
+
self.formatters = {}
|
17
|
+
|
18
|
+
module Flag
|
19
|
+
class << self
|
20
|
+
def call(result, **_options)
|
21
|
+
{"valid" => result.valid?}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
register :flag, Flag
|
26
|
+
|
27
|
+
module Basic
|
28
|
+
class << self
|
29
|
+
def call(result, **_options)
|
30
|
+
valid = result.valid?
|
31
|
+
key = valid ? "annotations" : "errors"
|
32
|
+
{
|
33
|
+
"valid" => valid,
|
34
|
+
key => collect_nodes(result, valid)
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def collect_nodes(node, valid, result = [])
|
41
|
+
return result if node.valid? != valid
|
42
|
+
|
43
|
+
key = valid ? "annotation" : "error"
|
44
|
+
result << node_data(node, key) if node.public_send(key)
|
45
|
+
|
46
|
+
node.children.each do |_, child|
|
47
|
+
collect_nodes(child, valid, result)
|
48
|
+
end
|
49
|
+
|
50
|
+
result
|
51
|
+
end
|
52
|
+
|
53
|
+
def node_data(node, key)
|
54
|
+
{
|
55
|
+
"instanceLocation" => node.instance.path.to_s,
|
56
|
+
"keywordLocation" => node.path.to_s,
|
57
|
+
"absoluteKeywordLocation" => node.absolute_uri.to_s,
|
58
|
+
key => node.public_send(key)
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
register :basic, Basic
|
64
|
+
|
65
|
+
module Detailed
|
66
|
+
class << self
|
67
|
+
def call(result, **_options)
|
68
|
+
valid = result.valid?
|
69
|
+
|
70
|
+
node_data(result, valid, true)
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def node_data(node, valid, first = false)
|
76
|
+
data = {
|
77
|
+
"valid" => valid,
|
78
|
+
"instanceLocation" => node.instance.path.to_s,
|
79
|
+
"keywordLocation" => node.path.to_s,
|
80
|
+
"absoluteKeywordLocation" => node.absolute_uri.to_s
|
81
|
+
}
|
82
|
+
|
83
|
+
child_key = valid ? "annotations" : "errors"
|
84
|
+
msg_key = valid ? "annotation" : "error"
|
85
|
+
|
86
|
+
child_data = node.children.filter_map do |_, child|
|
87
|
+
node_data(child, valid) if child.valid? == valid
|
88
|
+
end
|
89
|
+
|
90
|
+
if first || child_data.length > 1
|
91
|
+
data[child_key] = child_data
|
92
|
+
elsif child_data.length == 1
|
93
|
+
data = child_data[0]
|
94
|
+
elsif node.public_send(msg_key)
|
95
|
+
data[msg_key] = node.public_send(msg_key)
|
96
|
+
end
|
97
|
+
|
98
|
+
data
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
register :detailed, Detailed
|
103
|
+
|
104
|
+
module Verbose
|
105
|
+
class << self
|
106
|
+
def call(result, **_options)
|
107
|
+
node_data(result)
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def node_data(node)
|
113
|
+
valid = node.valid?
|
114
|
+
data = {
|
115
|
+
"valid" => valid,
|
116
|
+
"instanceLocation" => node.instance.path.to_s,
|
117
|
+
"keywordLocation" => node.path.to_s,
|
118
|
+
"absoluteKeywordLocation" => node.absolute_uri.to_s
|
119
|
+
}
|
120
|
+
msg_key = valid ? "annotation" : "error"
|
121
|
+
data[msg_key] = node.public_send(msg_key) if node.public_send(msg_key)
|
122
|
+
|
123
|
+
child_key = valid ? "annotations" : "errors"
|
124
|
+
child_data = node.children.map do |_, child|
|
125
|
+
node_data(child)
|
126
|
+
end
|
127
|
+
data[child_key] = child_data if child_data.length > 0
|
128
|
+
|
129
|
+
data
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
register :verbose, Verbose
|
134
|
+
end
|
135
|
+
end
|