File tree Expand file tree Collapse file tree
src/alterschema/canonicalizer/next Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,24 +25,17 @@ class EnumFilterByType final : public SchemaTransformRule {
2525 schema.at (" enum" ).is_array () && !schema.at (" enum" ).empty ());
2626
2727 const auto declared_types{parse_schema_type (schema.at (" type" ))};
28- const bool integer_matches_real {
28+ const bool integer_matches_integral {
2929 vocabularies.contains (Vocabularies::Known::JSON_Schema_Draft_6) &&
3030 declared_types.test (std::to_underlying (JSON::Type::Integer))};
3131
3232 this ->matching_indices_ .clear ();
3333 bool has_mismatch{false };
3434 std::size_t index{0 };
3535 for (const auto &value : schema.at (" enum" ).as_array ()) {
36- bool matches{declared_types.test (std::to_underlying (value.type ()))};
37- if (!matches && integer_matches_real) {
38- if (value.is_real () && std::floor (value.to_real ()) == value.to_real ()) {
39- matches = true ;
40- } else if (value.is_decimal () &&
41- value.to_decimal () == value.to_decimal ().to_integral ()) {
42- matches = true ;
43- }
44- }
45-
36+ const bool matches{
37+ declared_types.test (std::to_underlying (value.type ())) ||
38+ (integer_matches_integral && value.is_integral ())};
4639 if (matches) {
4740 this ->matching_indices_ .push_back (index);
4841 } else {
Original file line number Diff line number Diff line change @@ -25,27 +25,14 @@ class UnsatisfiableTypeAndEnum final : public SchemaTransformRule {
2525 schema.at (" enum" ).is_array () && !schema.at (" enum" ).empty ());
2626
2727 const auto declared_types{parse_schema_type (schema.at (" type" ))};
28- const bool integer_matches_real {
28+ const bool integer_matches_integral {
2929 vocabularies.contains (Vocabularies::Known::JSON_Schema_Draft_6) &&
3030 declared_types.test (std::to_underlying (JSON::Type::Integer))};
3131 ONLY_CONTINUE_IF (std::ranges::none_of (
3232 schema.at (" enum" ).as_array (),
33- [&declared_types, integer_matches_real](const auto &value) {
34- if (declared_types.test (std::to_underlying (value.type ()))) {
35- return true ;
36- }
37-
38- if (integer_matches_real && value.is_real () &&
39- std::floor (value.to_real ()) == value.to_real ()) {
40- return true ;
41- }
42-
43- if (integer_matches_real && value.is_decimal () &&
44- value.to_decimal () == value.to_decimal ().to_integral ()) {
45- return true ;
46- }
47-
48- return false ;
33+ [&declared_types, integer_matches_integral](const auto &value) {
34+ return declared_types.test (std::to_underlying (value.type ())) ||
35+ (integer_matches_integral && value.is_integral ());
4936 }));
5037 return true ;
5138 }
You can’t perform that action at this time.
0 commit comments