Skip to content

Commit

Permalink
Report schema resources on compiler steps (#914)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Aug 8, 2024
1 parent 332f59a commit 97078b4
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 14 deletions.
11 changes: 9 additions & 2 deletions src/jsonschema/compile_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ auto make(const SchemaCompilerSchemaContext &schema_context,
relative_schema_location(context),
context.base_instance_location,
keyword_location(schema_context),
schema_context.base.recompose(),
std::move(value),
std::move(condition)};
}
Expand All @@ -57,6 +58,7 @@ auto make(const SchemaCompilerSchemaContext &schema_context,
relative_schema_location(context),
context.base_instance_location,
keyword_location(schema_context),
schema_context.base.recompose(),
std::move(value),
std::move(condition),
std::move(data)};
Expand All @@ -74,6 +76,7 @@ auto make(const SchemaCompilerSchemaContext &schema_context,
relative_schema_location(context),
context.base_instance_location,
keyword_location(schema_context),
schema_context.base.recompose(),
std::move(value),
std::move(children),
std::move(condition)};
Expand All @@ -84,8 +87,12 @@ template <typename Step>
auto make(const SchemaCompilerSchemaContext &schema_context,
const SchemaCompilerDynamicContext &context, const std::size_t id,
SchemaCompilerTemplate &&children) -> Step {
return {relative_schema_location(context), context.base_instance_location,
keyword_location(schema_context), id, std::move(children)};
return {relative_schema_location(context),
context.base_instance_location,
keyword_location(schema_context),
schema_context.base.recompose(),
id,
std::move(children)};
}

inline auto type_condition(const SchemaCompilerSchemaContext &schema_context,
Expand Down
16 changes: 9 additions & 7 deletions src/jsonschema/compile_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ auto encode_step(const std::string_view category, const std::string_view type,
result.assign("relativeInstanceLocation",
JSON{to_string(step.relative_instance_location)});
result.assign("absoluteKeywordLocation", JSON{step.keyword_location});
result.assign("schemaResource", JSON{step.schema_resource});

if constexpr (requires { step.id; }) {
result.assign("id", JSON{step.id});
Expand Down Expand Up @@ -286,13 +287,14 @@ auto compiler_template_format_compare(const JSON::String &left,
static Rank rank{{"category", 0},
{"type", 1},
{"value", 2},
{"absoluteKeywordLocation", 3},
{"relativeSchemaLocation", 4},
{"relativeInstanceLocation", 5},
{"target", 6},
{"location", 7},
{"condition", 8},
{"children", 9}};
{"schemaResource", 3},
{"absoluteKeywordLocation", 4},
{"relativeSchemaLocation", 5},
{"relativeInstanceLocation", 6},
{"target", 7},
{"location", 8},
{"condition", 9},
{"children", 10}};

// We define and control all of these keywords, so if we are missing
// some here, then we did something wrong?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ using SchemaCompilerTemplate = std::vector<std::variant<
const Pointer relative_schema_location; \
const Pointer relative_instance_location; \
const std::string keyword_location; \
const std::string schema_resource; \
const SchemaCompilerStepValue<type> value; \
const SchemaCompilerTemplate condition; \
};
Expand All @@ -334,6 +335,7 @@ using SchemaCompilerTemplate = std::vector<std::variant<
const Pointer relative_schema_location; \
const Pointer relative_instance_location; \
const std::string keyword_location; \
const std::string schema_resource; \
const SchemaCompilerStepValue<type> value; \
const SchemaCompilerTemplate condition; \
const data_type data; \
Expand All @@ -345,6 +347,7 @@ using SchemaCompilerTemplate = std::vector<std::variant<
const Pointer relative_schema_location; \
const Pointer relative_instance_location; \
const std::string keyword_location; \
const std::string schema_resource; \
const SchemaCompilerStepValue<type> value; \
const SchemaCompilerTemplate children; \
const SchemaCompilerTemplate condition; \
Expand All @@ -355,6 +358,7 @@ using SchemaCompilerTemplate = std::vector<std::variant<
const Pointer relative_schema_location; \
const Pointer relative_instance_location; \
const std::string keyword_location; \
const std::string schema_resource; \
const std::size_t id; \
const SchemaCompilerTemplate children; \
};
Expand Down
Loading

0 comments on commit 97078b4

Please sign in to comment.