-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinteger_bounded_8_bit.h
More file actions
39 lines (37 loc) · 1.85 KB
/
Copy pathinteger_bounded_8_bit.h
File metadata and controls
39 lines (37 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class IntegerBounded8Bit final : public sourcemeta::blaze::SchemaTransformRule {
public:
using mutates = std::true_type;
using reframe_after_transform = std::true_type;
IntegerBounded8Bit()
: sourcemeta::blaze::SchemaTransformRule{"integer_bounded_8_bit", ""} {};
[[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 &location,
const sourcemeta::core::SchemaWalker &,
const sourcemeta::core::SchemaResolver &) const
-> sourcemeta::blaze::SchemaTransformRule::Result override {
return location.dialect == "https://json-schema.org/draft/2020-12/schema" &&
vocabularies.contains(sourcemeta::core::Vocabularies::Known::
JSON_Schema_2020_12_Validation) &&
schema.is_object() && schema.defines("type") &&
schema.at("type").to_string() == "integer" &&
schema.defines("minimum") && schema.defines("maximum") &&
sourcemeta::core::is_byte(schema.at("maximum").to_integer() -
schema.at("minimum").to_integer()) &&
!schema.defines("multipleOf");
}
auto transform(sourcemeta::core::JSON &schema,
const sourcemeta::blaze::SchemaTransformRule::Result &) const
-> void override {
auto minimum = schema.at("minimum");
auto maximum = schema.at("maximum");
auto options = sourcemeta::core::JSON::make_object();
options.assign("minimum", std::move(minimum));
options.assign("maximum", std::move(maximum));
options.assign("multiplier", sourcemeta::core::JSON{1});
make_encoding(schema, "BOUNDED_MULTIPLE_8BITS_ENUM_FIXED", options);
}
};