Skip to content

Commit

Permalink
Introduce a new LoopPropertiesType(Strict) compiler step
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Sep 23, 2024
1 parent a4c71c9 commit 6e0d0e6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/jsonschema/compile_describe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,16 @@ struct DescribeVisitor {
return message.str();
}

auto operator()(const SchemaCompilerLoopPropertiesType &) const
-> std::string {
return unknown();
}

auto operator()(const SchemaCompilerLoopPropertiesTypeStrict &) const
-> std::string {
return unknown();
}

auto operator()(const SchemaCompilerLoopKeys &) const -> std::string {
assert(this->keyword == "propertyNames");
assert(this->target.is_object());
Expand Down
3 changes: 3 additions & 0 deletions src/jsonschema/compile_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ struct StepVisitor {
HANDLE_STEP("loop", "properties-no-annotation",
SchemaCompilerLoopPropertiesNoAnnotation)
HANDLE_STEP("loop", "properties-except", SchemaCompilerLoopPropertiesExcept)
HANDLE_STEP("loop", "properties-type", SchemaCompilerLoopPropertiesType)
HANDLE_STEP("loop", "properties-type-strict",
SchemaCompilerLoopPropertiesTypeStrict)
HANDLE_STEP("loop", "keys", SchemaCompilerLoopKeys)
HANDLE_STEP("loop", "items", SchemaCompilerLoopItems)
HANDLE_STEP("loop", "items-unmarked", SchemaCompilerLoopItemsUnmarked)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ struct SchemaCompilerLoopProperties;
struct SchemaCompilerLoopPropertiesRegex;
struct SchemaCompilerLoopPropertiesNoAnnotation;
struct SchemaCompilerLoopPropertiesExcept;
struct SchemaCompilerLoopPropertiesType;
struct SchemaCompilerLoopPropertiesTypeStrict;
struct SchemaCompilerLoopKeys;
struct SchemaCompilerLoopItems;
struct SchemaCompilerLoopItemsUnmarked;
Expand Down Expand Up @@ -214,7 +216,8 @@ using SchemaCompilerTemplate = std::vector<std::variant<
SchemaCompilerLogicalWhenArraySizeEqual, SchemaCompilerLoopPropertiesMatch,
SchemaCompilerLoopProperties, SchemaCompilerLoopPropertiesRegex,
SchemaCompilerLoopPropertiesNoAnnotation,
SchemaCompilerLoopPropertiesExcept, SchemaCompilerLoopKeys,
SchemaCompilerLoopPropertiesExcept, SchemaCompilerLoopPropertiesType,
SchemaCompilerLoopPropertiesTypeStrict, SchemaCompilerLoopKeys,
SchemaCompilerLoopItems, SchemaCompilerLoopItemsUnmarked,
SchemaCompilerLoopItemsUnevaluated, SchemaCompilerLoopContains,
SchemaCompilerControlLabel, SchemaCompilerControlMark,
Expand Down Expand Up @@ -490,6 +493,16 @@ DEFINE_STEP_APPLICATOR(Loop, PropertiesNoAnnotation, SchemaCompilerValueStrings)
DEFINE_STEP_APPLICATOR(Loop, PropertiesExcept,
SchemaCompilerValuePropertyFilter)

/// @ingroup jsonschema_compiler_instructions
/// @brief Represents a compiler step that checks every object property is of a
/// given type
DEFINE_STEP_APPLICATOR(Loop, PropertiesType, SchemaCompilerValueType)

/// @ingroup jsonschema_compiler_instructions
/// @brief Represents a compiler step that checks every object property is of a
/// given type (strict mode)
DEFINE_STEP_APPLICATOR(Loop, PropertiesTypeStrict, SchemaCompilerValueType)

/// @ingroup jsonschema_compiler_instructions
/// @brief Represents a compiler step that loops over object property keys
DEFINE_STEP_APPLICATOR(Loop, Keys, SchemaCompilerValueNone)
Expand Down

0 comments on commit 6e0d0e6

Please sign in to comment.