-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Juan Cruz Viotti <[email protected]>
- Loading branch information
Showing
5 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class DuplicateAllOfBranches final : public Rule { | ||
public: | ||
DuplicateAllOfBranches() | ||
: Rule{"duplicate_allof_branches", | ||
"Setting duplicate subschemas in `allOf` is redundant, as it " | ||
"produces " | ||
"unnecessary additional validation that is guaranteed to not " | ||
"affect the validation result"} {}; | ||
|
||
[[nodiscard]] auto | ||
condition(const sourcemeta::jsontoolkit::JSON &schema, const std::string &, | ||
const std::set<std::string> &vocabularies, | ||
const sourcemeta::jsontoolkit::Pointer &) const -> bool override { | ||
return contains_any( | ||
vocabularies, | ||
{"https://json-schema.org/draft/2020-12/vocab/applicator", | ||
"https://json-schema.org/draft/2019-09/vocab/applicator", | ||
"http://json-schema.org/draft-07/schema#", | ||
"http://json-schema.org/draft-06/schema#", | ||
"http://json-schema.org/draft-04/schema#"}) && | ||
schema.is_object() && schema.defines("allOf") && | ||
schema.at("allOf").is_array() && !schema.at("allOf").unique(); | ||
} | ||
|
||
auto transform(Transformer &transformer) const -> void override { | ||
auto collection = transformer.schema().at("allOf"); | ||
std::sort(collection.as_array().begin(), collection.as_array().end()); | ||
auto last = | ||
std::unique(collection.as_array().begin(), collection.as_array().end()); | ||
collection.erase(last, collection.as_array().end()); | ||
transformer.replace({"allOf"}, std::move(collection)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class DuplicateAnyOfBranches final : public Rule { | ||
public: | ||
DuplicateAnyOfBranches() | ||
: Rule{"duplicate_anyof_branches", | ||
"Setting duplicate subschemas in `anyOf` is redundant, as it " | ||
"produces " | ||
"unnecessary additional validation that is guaranteed to not " | ||
"affect the validation result"} {}; | ||
|
||
[[nodiscard]] auto | ||
condition(const sourcemeta::jsontoolkit::JSON &schema, const std::string &, | ||
const std::set<std::string> &vocabularies, | ||
const sourcemeta::jsontoolkit::Pointer &) const -> bool override { | ||
return contains_any( | ||
vocabularies, | ||
{"https://json-schema.org/draft/2020-12/vocab/applicator", | ||
"https://json-schema.org/draft/2019-09/vocab/applicator", | ||
"http://json-schema.org/draft-07/schema#", | ||
"http://json-schema.org/draft-06/schema#", | ||
"http://json-schema.org/draft-04/schema#"}) && | ||
schema.is_object() && schema.defines("anyOf") && | ||
schema.at("anyOf").is_array() && !schema.at("anyOf").unique(); | ||
} | ||
|
||
auto transform(Transformer &transformer) const -> void override { | ||
auto collection = transformer.schema().at("anyOf"); | ||
std::sort(collection.as_array().begin(), collection.as_array().end()); | ||
auto last = | ||
std::unique(collection.as_array().begin(), collection.as_array().end()); | ||
collection.erase(last, collection.as_array().end()); | ||
transformer.replace({"anyOf"}, std::move(collection)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters