Skip to content

Commit ea1a0c6

Browse files
authored
Fix vocabularies() for Draft 2, Draft 1, and Draft 0 (#1775)
Fixes: #1774 Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent c5ded55 commit ea1a0c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+91
-75
lines changed

src/core/jsonschema/bundle.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,13 @@ auto bundle(sourcemeta::core::JSON &schema, const SchemaWalker &walker,
183183
vocabularies.contains("http://json-schema.org/draft-03/schema#") ||
184184
vocabularies.contains(
185185
"http://json-schema.org/draft-02/hyper-schema#") ||
186+
vocabularies.contains("http://json-schema.org/draft-02/schema#") ||
186187
vocabularies.contains(
187188
"http://json-schema.org/draft-01/hyper-schema#") ||
189+
vocabularies.contains("http://json-schema.org/draft-01/schema#") ||
188190
vocabularies.contains(
189-
"http://json-schema.org/draft-00/hyper-schema#")) {
191+
"http://json-schema.org/draft-00/hyper-schema#") ||
192+
vocabularies.contains("http://json-schema.org/draft-00/schema#")) {
190193
frame.analyse(schema, walker, resolver, default_dialect);
191194
if (frame.standalone()) {
192195
return;

src/core/jsonschema/jsonschema.cc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,24 @@ auto sourcemeta::core::vocabularies(const SchemaResolver &resolver,
383383
}
384384

385385
/*
386-
* (1) If the base dialect is pre-vocabularies, then the
386+
* (1) If the dialect is pre-vocabularies, then the
387+
* dialect itself is conceptually the only vocabulary
388+
*/
389+
390+
// This is an exhaustive list of all official dialects in the pre-vocabulary
391+
// world
392+
if (dialect == "http://json-schema.org/draft-07/schema#" ||
393+
dialect == "http://json-schema.org/draft-06/schema#" ||
394+
dialect == "http://json-schema.org/draft-04/schema#" ||
395+
dialect == "http://json-schema.org/draft-03/schema#" ||
396+
dialect == "http://json-schema.org/draft-02/schema#" ||
397+
dialect == "http://json-schema.org/draft-01/schema#" ||
398+
dialect == "http://json-schema.org/draft-00/schema#") {
399+
return {{dialect, true}};
400+
}
401+
402+
/*
403+
* (2) If the base dialect is pre-vocabularies, then the
387404
* base dialect itself is conceptually the only vocabulary
388405
*/
389406

@@ -403,7 +420,7 @@ auto sourcemeta::core::vocabularies(const SchemaResolver &resolver,
403420
}
404421

405422
/*
406-
* (2) If the dialect is vocabulary aware, then fetch such dialect
423+
* (3) If the dialect is vocabulary aware, then fetch such dialect
407424
*/
408425

409426
const std::optional<sourcemeta::core::JSON> maybe_schema_dialect{
@@ -421,7 +438,7 @@ auto sourcemeta::core::vocabularies(const SchemaResolver &resolver,
421438
schema_dialect.at("$id").to_string() == dialect);
422439

423440
/*
424-
* (3) Retrieve the vocabularies explicitly or implicitly declared by the
441+
* (4) Retrieve the vocabularies explicitly or implicitly declared by the
425442
* dialect
426443
*/
427444

src/extension/alterschema/canonicalizer/min_items_implicit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class MinItemsImplicit final : public SchemaTransformRule {
1818
"http://json-schema.org/draft-06/schema#",
1919
"http://json-schema.org/draft-04/schema#",
2020
"http://json-schema.org/draft-03/schema#",
21-
"http://json-schema.org/draft-02/hyper-schema#",
22-
"http://json-schema.org/draft-01/hyper-schema#"}) &&
21+
"http://json-schema.org/draft-02/schema#",
22+
"http://json-schema.org/draft-01/schema#"}) &&
2323
schema.is_object() && schema.defines("type") &&
2424
schema.at("type").is_string() &&
2525
schema.at("type").to_string() == "array" &&

src/extension/alterschema/canonicalizer/min_length_implicit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class MinLengthImplicit final : public SchemaTransformRule {
2222
"http://json-schema.org/draft-06/schema#",
2323
"http://json-schema.org/draft-04/schema#",
2424
"http://json-schema.org/draft-03/schema#",
25-
"http://json-schema.org/draft-02/hyper-schema#",
26-
"http://json-schema.org/draft-01/hyper-schema#"}) &&
25+
"http://json-schema.org/draft-02/schema#",
26+
"http://json-schema.org/draft-01/schema#"}) &&
2727
schema.is_object() && schema.defines("type") &&
2828
schema.at("type").is_string() &&
2929
schema.at("type").to_string() == "string" &&

src/extension/alterschema/canonicalizer/properties_implicit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class PropertiesImplicit final : public SchemaTransformRule {
2727
"http://json-schema.org/draft-06/schema#",
2828
"http://json-schema.org/draft-04/schema#",
2929
"http://json-schema.org/draft-03/schema#",
30-
"http://json-schema.org/draft-02/hyper-schema#",
31-
"http://json-schema.org/draft-01/hyper-schema#"})) &&
30+
"http://json-schema.org/draft-02/schema#",
31+
"http://json-schema.org/draft-01/schema#"})) &&
3232
schema.is_object() && schema.defines("type") &&
3333
schema.at("type").is_string() &&
3434
schema.at("type").to_string() == "object" &&

src/extension/alterschema/canonicalizer/type_boolean_as_enum.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class TypeBooleanAsEnum final : public SchemaTransformRule {
2323
"http://json-schema.org/draft-06/schema#",
2424
"http://json-schema.org/draft-04/schema#",
2525
"http://json-schema.org/draft-03/schema#",
26-
"http://json-schema.org/draft-02/hyper-schema#",
27-
"http://json-schema.org/draft-01/hyper-schema#"}) &&
26+
"http://json-schema.org/draft-02/schema#",
27+
"http://json-schema.org/draft-01/schema#"}) &&
2828
schema.is_object() && schema.defines("type") &&
2929
schema.at("type").is_string() &&
3030
schema.at("type").to_string() == "boolean" &&

src/extension/alterschema/canonicalizer/type_null_as_enum.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class TypeNullAsEnum final : public SchemaTransformRule {
2323
"http://json-schema.org/draft-06/schema#",
2424
"http://json-schema.org/draft-04/schema#",
2525
"http://json-schema.org/draft-03/schema#",
26-
"http://json-schema.org/draft-02/hyper-schema#",
27-
"http://json-schema.org/draft-01/hyper-schema#"}) &&
26+
"http://json-schema.org/draft-02/schema#",
27+
"http://json-schema.org/draft-01/schema#"}) &&
2828
schema.is_object() && schema.defines("type") &&
2929
schema.at("type").is_string() &&
3030
schema.at("type").to_string() == "null" && !schema.defines("enum") &&

src/extension/alterschema/canonicalizer/type_union_implicit.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class TypeUnionImplicit final : public SchemaTransformRule {
2525
"http://json-schema.org/draft-06/schema#",
2626
"http://json-schema.org/draft-04/schema#",
2727
"http://json-schema.org/draft-03/schema#",
28-
"http://json-schema.org/draft-02/hyper-schema#",
29-
"http://json-schema.org/draft-01/hyper-schema#",
30-
"http://json-schema.org/draft-00/hyper-schema#"})) {
28+
"http://json-schema.org/draft-02/schema#",
29+
"http://json-schema.org/draft-01/schema#",
30+
"http://json-schema.org/draft-00/schema#"})) {
3131
if (schema.defines("type")) {
3232
return false;
3333
}

src/extension/alterschema/linter/additional_properties_default.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class AdditionalPropertiesDefault final : public SchemaTransformRule {
2323
"http://json-schema.org/draft-06/schema#",
2424
"http://json-schema.org/draft-04/schema#",
2525
"http://json-schema.org/draft-03/schema#",
26+
"http://json-schema.org/draft-02/schema#",
2627
"http://json-schema.org/draft-02/hyper-schema#",
28+
"http://json-schema.org/draft-01/schema#",
2729
"http://json-schema.org/draft-01/hyper-schema#"}) &&
2830
schema.is_object() && schema.defines("additionalProperties") &&
2931
((schema.at("additionalProperties").is_boolean() &&

src/extension/alterschema/linter/drop_non_array_keywords_draft0.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ class DropNonArrayKeywords_Draft0 final : public SchemaTransformRule {
1515
const sourcemeta::core::SchemaWalker &,
1616
const sourcemeta::core::SchemaResolver &) const
1717
-> sourcemeta::core::SchemaTransformRule::Result override {
18-
return vocabularies.contains(
19-
"http://json-schema.org/draft-00/hyper-schema#") &&
18+
return vocabularies.contains("http://json-schema.org/draft-00/schema#") &&
2019
schema.is_object() && schema.defines("type") &&
2120
schema.at("type").is_string() &&
2221
schema.at("type").to_string() == "array" &&

0 commit comments

Comments
 (0)