-
-
Notifications
You must be signed in to change notification settings - Fork 13
Fix a few canonicalizer Draft 4 bugs #706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,37 @@ class ExclusiveMinimumBooleanIntegerFold final : public SchemaTransformRule { | |
| } | ||
|
|
||
| auto transform(JSON &schema, const Result &) const -> void override { | ||
| auto new_minimum = schema.at("minimum"); | ||
| new_minimum += sourcemeta::core::JSON{1}; | ||
| schema.assign("minimum", std::move(new_minimum)); | ||
| const auto &minimum{schema.at("minimum")}; | ||
| if (minimum.is_integer()) { | ||
| auto new_minimum = minimum; | ||
| new_minimum += sourcemeta::core::JSON{1}; | ||
| schema.assign("minimum", std::move(new_minimum)); | ||
| } else if (minimum.is_decimal()) { | ||
| auto current{minimum.to_decimal()}; | ||
| auto ceiled{current.to_integral()}; | ||
| if (ceiled < current) { | ||
| ceiled += sourcemeta::core::Decimal{1}; | ||
| } | ||
|
|
||
| if (current.is_integer()) { | ||
| ceiled += sourcemeta::core::Decimal{1}; | ||
| } | ||
|
|
||
| if (ceiled.is_int64()) { | ||
| schema.assign("minimum", sourcemeta::core::JSON{ceiled.to_int64()}); | ||
| } else { | ||
| schema.assign("minimum", sourcemeta::core::JSON{std::move(ceiled)}); | ||
| } | ||
| } else { | ||
| const auto value{minimum.to_real()}; | ||
| auto ceiled{static_cast<std::int64_t>(std::ceil(value))}; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. src/alterschema/canonicalizer/next/exclusive_minimum_boolean_integer_fold.h:56: Severity: medium 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| if (std::ceil(value) == value) { | ||
| ceiled += 1; | ||
| } | ||
|
|
||
| schema.assign("minimum", sourcemeta::core::JSON{ceiled}); | ||
| } | ||
|
|
||
| schema.erase("exclusiveMinimum"); | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| class UnsatisfiableExclusiveEqualBounds final : public SchemaTransformRule { | ||
| public: | ||
| using mutates = std::true_type; | ||
| using reframe_after_transform = std::false_type; | ||
| UnsatisfiableExclusiveEqualBounds() | ||
| : SchemaTransformRule{ | ||
| "unsatisfiable_exclusive_equal_bounds", | ||
| "When `minimum` equals `maximum` and either boolean " | ||
| "`exclusiveMinimum` or `exclusiveMaximum` is true, " | ||
| "no value can satisfy the schema"} {}; | ||
|
|
||
| [[nodiscard]] auto | ||
| condition(const sourcemeta::core::JSON &schema, | ||
| const sourcemeta::core::JSON &, | ||
| const sourcemeta::core::Vocabularies &vocabularies, | ||
| const sourcemeta::core::SchemaFrame &, | ||
| const sourcemeta::core::SchemaFrame::Location &, | ||
| const sourcemeta::core::SchemaWalker &, | ||
| const sourcemeta::core::SchemaResolver &) const | ||
| -> SchemaTransformRule::Result override { | ||
| ONLY_CONTINUE_IF( | ||
|
jviotti marked this conversation as resolved.
|
||
| vocabularies.contains(Vocabularies::Known::JSON_Schema_Draft_4) && | ||
| schema.is_object() && schema.defines("type") && | ||
| schema.at("type").is_string() && | ||
| (schema.at("type").to_string() == "number" || | ||
| schema.at("type").to_string() == "integer") && | ||
| schema.defines("minimum") && schema.at("minimum").is_number() && | ||
| schema.defines("maximum") && schema.at("maximum").is_number() && | ||
| schema.at("minimum") == schema.at("maximum")); | ||
|
|
||
| const bool exclusive_min{schema.defines("exclusiveMinimum") && | ||
| schema.at("exclusiveMinimum").is_boolean() && | ||
| schema.at("exclusiveMinimum").to_boolean()}; | ||
| const bool exclusive_max{schema.defines("exclusiveMaximum") && | ||
| schema.at("exclusiveMaximum").is_boolean() && | ||
| schema.at("exclusiveMaximum").to_boolean()}; | ||
| ONLY_CONTINUE_IF(exclusive_min || exclusive_max); | ||
| return true; | ||
| } | ||
|
|
||
| auto transform(JSON &schema, const Result &) const -> void override { | ||
| schema.into(JSON{false}); | ||
| } | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.