|
| 1 | +class AdditionalPropertiesDefault final : public Rule { |
| 2 | +public: |
| 3 | + AdditionalPropertiesDefault() |
| 4 | + : Rule{"additional_properties_default", |
| 5 | + "Setting the `additionalProperties` keyword to the true schema " |
| 6 | + "does not add any further constraint"} {}; |
| 7 | + |
| 8 | + [[nodiscard]] auto |
| 9 | + condition(const sourcemeta::jsontoolkit::JSON &schema, const std::string &, |
| 10 | + const std::set<std::string> &vocabularies, |
| 11 | + const sourcemeta::jsontoolkit::Pointer &) const -> bool override { |
| 12 | + return contains_any( |
| 13 | + vocabularies, |
| 14 | + {"https://json-schema.org/draft/2020-12/vocab/applicator", |
| 15 | + "https://json-schema.org/draft/2019-09/vocab/applicator", |
| 16 | + "http://json-schema.org/draft-07/schema#", |
| 17 | + "http://json-schema.org/draft-06/schema#", |
| 18 | + "http://json-schema.org/draft-04/schema#", |
| 19 | + "http://json-schema.org/draft-03/schema#", |
| 20 | + "http://json-schema.org/draft-02/hyper-schema#", |
| 21 | + "http://json-schema.org/draft-01/hyper-schema#"}) && |
| 22 | + schema.is_object() && schema.defines("additionalProperties") && |
| 23 | + ((schema.at("additionalProperties").is_boolean() && |
| 24 | + schema.at("additionalProperties").to_boolean()) || |
| 25 | + (schema.at("additionalProperties").is_object() && |
| 26 | + schema.at("additionalProperties").empty())); |
| 27 | + } |
| 28 | + |
| 29 | + auto transform(Transformer &transformer) const -> void override { |
| 30 | + transformer.erase("additionalProperties"); |
| 31 | + } |
| 32 | +}; |
0 commit comments