Skip to content

Commit

Permalink
[WIP] Make schema walkers report instance location pointer templates
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Feb 4, 2025
1 parent 26d3205 commit 8ab64ec
Show file tree
Hide file tree
Showing 13 changed files with 676 additions and 202 deletions.
25 changes: 13 additions & 12 deletions src/core/jsonschema/include/sourcemeta/core/jsonschema_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ enum class SchemaKeywordType : std::uint8_t {
/// The JSON Schema keyword is considered to be a comment without any
/// additional meaning
Comment,
/// The JSON Schema keyword is a reserved location that potentially
/// takes an object as argument, whose values are potentially
/// JSON Schema definitions
LocationMembers,

/// The JSON Schema keyword is an applicator that potentially
/// takes an object as argument, whose values are potentially
Expand Down Expand Up @@ -98,6 +102,11 @@ enum class SchemaKeywordType : std::uint8_t {
/// as an argument
/// The instance traverses based on the element indexes
ApplicatorElementsTraverseItem,
/// The JSON Schema keyword is an applicator that may take a JSON Schema
/// definition or an array of potentially JSON Schema definitions
/// as an argument
/// The instance traverses to any item or based on the element indexes
ApplicatorValueOrElementsTraverseAnyItemOrItem,

/// The JSON Schema keyword is an applicator that potentially
/// takes a JSON Schema definition as an argument
Expand Down Expand Up @@ -133,20 +142,8 @@ enum class SchemaKeywordType : std::uint8_t {
ApplicatorMembersInPlace,
/// The JSON Schema keyword is an applicator that may take a JSON Schema
/// definition or an array of potentially JSON Schema definitions
/// as an argument
ApplicatorValueOrElements,
/// The JSON Schema keyword is an applicator that may take a JSON Schema
/// definition or an array of potentially JSON Schema definitions
/// as an argument without affecting the instance location
ApplicatorValueOrElementsInPlace,
/// The JSON Schema keyword is an applicator that may take an array of
/// potentially JSON Schema definitions or an object whose values are
/// potentially JSON Schema definitions as an argument
ApplicatorElementsOrMembers,
/// The JSON Schema keyword is a reserved location that potentially
/// takes an object as argument, whose values are potentially
/// JSON Schema definitions
LocationMembers,
};
#if defined(__GNUC__)
#pragma GCC diagnostic pop
Expand Down Expand Up @@ -198,7 +195,11 @@ struct SchemaIteratorEntry {
std::optional<std::string> dialect;
std::map<std::string, bool> vocabularies;
std::optional<std::string> base_dialect;
// TODO: Do we really need a full copy of the JSON value if the client
// can get it through the JSON Pointer if needed?
JSON value;
PointerTemplate instance_location;
bool orphan;
};

} // namespace sourcemeta::core
Expand Down
41 changes: 24 additions & 17 deletions src/core/jsonschema/official_walker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ auto sourcemeta::core::schema_official_walker(
WALK(HTTPS_BASE "2019-09/vocab/applicator", "unevaluatedItems",
ApplicatorValueTraverseAnyItem, "items", "additionalItems")
WALK(HTTPS_BASE "2019-09/vocab/applicator", "items",
ApplicatorValueOrElements)
ApplicatorValueOrElementsTraverseAnyItemOrItem)
WALK_MAYBE_DEPENDENT(HTTPS_BASE "2019-09/vocab/applicator", "contains",
ApplicatorValueTraverseAnyItem,
HTTPS_BASE "2019-09/vocab/validation", "minContains",
"maxContains")
WALK(HTTPS_BASE "2019-09/vocab/applicator", "additionalItems",
ApplicatorValue, "items")
ApplicatorValueTraverseAnyItem, "items")
// For the purpose of compiler optimizations
WALK_MAYBE_DEPENDENT(HTTPS_BASE "2019-09/vocab/validation", "type", Assertion,
HTTPS_BASE "2019-09/vocab/applicator", "properties")
Expand Down Expand Up @@ -235,9 +235,9 @@ auto sourcemeta::core::schema_official_walker(
WALK_ANY(HTTP_BASE "draft-07/schema#", HTTP_BASE "draft-07/hyper-schema#",
"pattern", Assertion, "$ref")
WALK_ANY(HTTP_BASE "draft-07/schema#", HTTP_BASE "draft-07/hyper-schema#",
"items", ApplicatorValueOrElements, "$ref")
"items", ApplicatorValueOrElementsTraverseAnyItemOrItem, "$ref")
WALK_ANY(HTTP_BASE "draft-07/schema#", HTTP_BASE "draft-07/hyper-schema#",
"additionalItems", ApplicatorValue, "items")
"additionalItems", ApplicatorValueTraverseAnyItem, "items")
WALK_ANY(HTTP_BASE "draft-07/schema#", HTTP_BASE "draft-07/hyper-schema#",
"maxItems", Assertion, "$ref")
WALK_ANY(HTTP_BASE "draft-07/schema#", HTTP_BASE "draft-07/hyper-schema#",
Expand Down Expand Up @@ -349,9 +349,9 @@ auto sourcemeta::core::schema_official_walker(
WALK_ANY(HTTP_BASE "draft-06/schema#", HTTP_BASE "draft-06/hyper-schema#",
"pattern", Assertion, "$ref")
WALK_ANY(HTTP_BASE "draft-06/schema#", HTTP_BASE "draft-06/hyper-schema#",
"items", ApplicatorValueOrElements, "$ref")
"items", ApplicatorValueOrElementsTraverseAnyItemOrItem, "$ref")
WALK_ANY(HTTP_BASE "draft-06/schema#", HTTP_BASE "draft-06/hyper-schema#",
"additionalItems", ApplicatorValue, "items")
"additionalItems", ApplicatorValueTraverseAnyItem, "items")
WALK_ANY(HTTP_BASE "draft-06/schema#", HTTP_BASE "draft-06/hyper-schema#",
"maxItems", Assertion, "$ref")
WALK_ANY(HTTP_BASE "draft-06/schema#", HTTP_BASE "draft-06/hyper-schema#",
Expand Down Expand Up @@ -451,9 +451,9 @@ auto sourcemeta::core::schema_official_walker(
WALK_ANY(HTTP_BASE "draft-04/schema#", HTTP_BASE "draft-04/hyper-schema#",
"pattern", Assertion, "$ref")
WALK_ANY(HTTP_BASE "draft-04/schema#", HTTP_BASE "draft-04/hyper-schema#",
"items", ApplicatorValueOrElements, "$ref")
"items", ApplicatorValueOrElementsTraverseAnyItemOrItem, "$ref")
WALK_ANY(HTTP_BASE "draft-04/schema#", HTTP_BASE "draft-04/hyper-schema#",
"additionalItems", ApplicatorValue, "items")
"additionalItems", ApplicatorValueTraverseAnyItem, "items")
WALK_ANY(HTTP_BASE "draft-04/schema#", HTTP_BASE "draft-04/hyper-schema#",
"maxItems", Assertion, "$ref")
WALK_ANY(HTTP_BASE "draft-04/schema#", HTTP_BASE "draft-04/hyper-schema#",
Expand Down Expand Up @@ -523,9 +523,10 @@ auto sourcemeta::core::schema_official_walker(
ApplicatorMembersTraversePropertyRegex, "$ref")
WALK(HTTP_BASE "draft-03/schema#", "additionalProperties",
ApplicatorValueTraverseAnyProperty, "properties", "patternProperties")
WALK(HTTP_BASE "draft-03/schema#", "items", ApplicatorValueOrElements, "$ref")
WALK(HTTP_BASE "draft-03/schema#", "additionalItems", ApplicatorValue,
"items")
WALK(HTTP_BASE "draft-03/schema#", "items",
ApplicatorValueOrElementsTraverseAnyItemOrItem, "$ref")
WALK(HTTP_BASE "draft-03/schema#", "additionalItems",
ApplicatorValueTraverseAnyItem, "items")
WALK(HTTP_BASE "draft-03/schema#", "minItems", Assertion, "$ref")
WALK(HTTP_BASE "draft-03/schema#", "maxItems", Assertion, "$ref")
WALK(HTTP_BASE "draft-03/schema#", "uniqueItems", Assertion, "$ref")
Expand Down Expand Up @@ -558,7 +559,8 @@ auto sourcemeta::core::schema_official_walker(
WALK(HTTP_BASE "draft-02/schema#", "$schema", Other)
WALK(HTTP_BASE "draft-02/schema#", "id", Other)
WALK(HTTP_BASE "draft-02/schema#", "$ref", Reference)
WALK(HTTP_BASE "draft-02/schema#", "items", ApplicatorValueOrElements)
WALK(HTTP_BASE "draft-02/schema#", "items",
ApplicatorValueOrElementsTraverseAnyItemOrItem)
WALK(HTTP_BASE "draft-02/schema#", "properties",
ApplicatorMembersTraversePropertyStatic)
WALK(HTTP_BASE "draft-02/schema#", "additionalProperties",
Expand Down Expand Up @@ -588,7 +590,8 @@ auto sourcemeta::core::schema_official_walker(
WALK(HTTP_BASE "draft-02/hyper-schema#", "requires", ApplicatorValueInPlace)
WALK(HTTP_BASE "draft-02/hyper-schema#", "targetSchema", ApplicatorValue)
WALK(HTTP_BASE "draft-02/hyper-schema#", "type", ApplicatorElements)
WALK(HTTP_BASE "draft-02/hyper-schema#", "items", ApplicatorValueOrElements)
WALK(HTTP_BASE "draft-02/hyper-schema#", "items",
ApplicatorValueOrElementsTraverseAnyItemOrItem)
WALK(HTTP_BASE "draft-02/hyper-schema#", "properties",
ApplicatorMembersTraversePropertyStatic)
WALK(HTTP_BASE "draft-02/hyper-schema#", "extends",
Expand All @@ -600,7 +603,8 @@ auto sourcemeta::core::schema_official_walker(
WALK(HTTP_BASE "draft-01/schema#", "$schema", Other)
WALK(HTTP_BASE "draft-01/schema#", "id", Other)
WALK(HTTP_BASE "draft-01/schema#", "$ref", Reference)
WALK(HTTP_BASE "draft-01/schema#", "items", ApplicatorValueOrElements)
WALK(HTTP_BASE "draft-01/schema#", "items",
ApplicatorValueOrElementsTraverseAnyItemOrItem)
WALK(HTTP_BASE "draft-01/schema#", "properties",
ApplicatorMembersTraversePropertyStatic)
WALK(HTTP_BASE "draft-01/schema#", "additionalProperties",
Expand Down Expand Up @@ -628,7 +632,8 @@ auto sourcemeta::core::schema_official_walker(
WALK(HTTP_BASE "draft-01/schema#", "optional", Assertion)
WALK(HTTP_BASE "draft-01/schema#", "maxDecimal", Assertion)
WALK(HTTP_BASE "draft-01/hyper-schema#", "type", ApplicatorElements)
WALK(HTTP_BASE "draft-01/hyper-schema#", "items", ApplicatorValueOrElements)
WALK(HTTP_BASE "draft-01/hyper-schema#", "items",
ApplicatorValueOrElementsTraverseAnyItemOrItem)
WALK(HTTP_BASE "draft-01/hyper-schema#", "properties",
ApplicatorMembersTraversePropertyStatic)
WALK(HTTP_BASE "draft-01/hyper-schema#", "extends",
Expand All @@ -641,7 +646,8 @@ auto sourcemeta::core::schema_official_walker(
WALK(HTTP_BASE "draft-00/schema#", "$schema", Other)
WALK(HTTP_BASE "draft-00/schema#", "id", Other)
WALK(HTTP_BASE "draft-00/schema#", "$ref", Reference)
WALK(HTTP_BASE "draft-00/schema#", "items", ApplicatorValueOrElements)
WALK(HTTP_BASE "draft-00/schema#", "items",
ApplicatorValueOrElementsTraverseAnyItemOrItem)
WALK(HTTP_BASE "draft-00/schema#", "properties",
ApplicatorMembersTraversePropertyStatic)
WALK(HTTP_BASE "draft-00/schema#", "additionalProperties",
Expand Down Expand Up @@ -669,7 +675,8 @@ auto sourcemeta::core::schema_official_walker(
WALK(HTTP_BASE "draft-00/schema#", "optional", Assertion)
WALK(HTTP_BASE "draft-00/schema#", "maxDecimal", Assertion)
WALK(HTTP_BASE "draft-00/hyper-schema#", "type", ApplicatorElements)
WALK(HTTP_BASE "draft-00/hyper-schema#", "items", ApplicatorValueOrElements)
WALK(HTTP_BASE "draft-00/hyper-schema#", "items",
ApplicatorValueOrElementsTraverseAnyItemOrItem)
WALK(HTTP_BASE "draft-00/hyper-schema#", "properties",
ApplicatorMembersTraversePropertyStatic)
WALK(HTTP_BASE "draft-00/hyper-schema#", "extends",
Expand Down
Loading

0 comments on commit 8ab64ec

Please sign in to comment.