Skip to content

Commit

Permalink
Make the compiler permissible with integer reals on Draft 4 (#764)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Jun 7, 2024
1 parent 1175a47 commit d6587f0
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/jsonschema/default_compiler_draft4.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,90 +548,90 @@ auto compiler_draft4_validation_uniqueitems(

auto compiler_draft4_validation_maxlength(const SchemaCompilerContext &context)
-> SchemaCompilerTemplate {
assert(context.value.is_integer());
assert(context.value.is_integer() || context.value.is_integer_real());
assert(context.value.is_positive());

// TODO: As an optimization, if `minLength` is set to the same number, do
// a single size equality assertion
return {make<SchemaCompilerAssertionSizeLess>(
context,
SchemaCompilerValueUnsignedInteger{
static_cast<unsigned long>(context.value.to_integer()) + 1},
static_cast<unsigned long>(context.value.as_integer()) + 1},
type_condition(context, JSON::Type::String),
SchemaCompilerTargetType::Instance)};
}

auto compiler_draft4_validation_minlength(const SchemaCompilerContext &context)
-> SchemaCompilerTemplate {
assert(context.value.is_integer());
assert(context.value.is_integer() || context.value.is_integer_real());
assert(context.value.is_positive());

// TODO: As an optimization, if `maxLength` is set to the same number, do
// a single size equality assertion
return {make<SchemaCompilerAssertionSizeGreater>(
context,
SchemaCompilerValueUnsignedInteger{
static_cast<unsigned long>(context.value.to_integer()) - 1},
static_cast<unsigned long>(context.value.as_integer()) - 1},
type_condition(context, JSON::Type::String),
SchemaCompilerTargetType::Instance)};
}

auto compiler_draft4_validation_maxitems(const SchemaCompilerContext &context)
-> SchemaCompilerTemplate {
assert(context.value.is_integer());
assert(context.value.is_integer() || context.value.is_integer_real());
assert(context.value.is_positive());

// TODO: As an optimization, if `minItems` is set to the same number, do
// a single size equality assertion
return {make<SchemaCompilerAssertionSizeLess>(
context,
SchemaCompilerValueUnsignedInteger{
static_cast<unsigned long>(context.value.to_integer()) + 1},
static_cast<unsigned long>(context.value.as_integer()) + 1},
type_condition(context, JSON::Type::Array),
SchemaCompilerTargetType::Instance)};
}

auto compiler_draft4_validation_minitems(const SchemaCompilerContext &context)
-> SchemaCompilerTemplate {
assert(context.value.is_integer());
assert(context.value.is_integer() || context.value.is_integer_real());
assert(context.value.is_positive());

// TODO: As an optimization, if `maxItems` is set to the same number, do
// a single size equality assertion
return {make<SchemaCompilerAssertionSizeGreater>(
context,
SchemaCompilerValueUnsignedInteger{
static_cast<unsigned long>(context.value.to_integer()) - 1},
static_cast<unsigned long>(context.value.as_integer()) - 1},
type_condition(context, JSON::Type::Array),
SchemaCompilerTargetType::Instance)};
}

auto compiler_draft4_validation_maxproperties(
const SchemaCompilerContext &context) -> SchemaCompilerTemplate {
assert(context.value.is_integer());
assert(context.value.is_integer() || context.value.is_integer_real());
assert(context.value.is_positive());

// TODO: As an optimization, if `minProperties` is set to the same number, do
// a single size equality assertion
return {make<SchemaCompilerAssertionSizeLess>(
context,
SchemaCompilerValueUnsignedInteger{
static_cast<unsigned long>(context.value.to_integer()) + 1},
static_cast<unsigned long>(context.value.as_integer()) + 1},
type_condition(context, JSON::Type::Object),
SchemaCompilerTargetType::Instance)};
}

auto compiler_draft4_validation_minproperties(
const SchemaCompilerContext &context) -> SchemaCompilerTemplate {
assert(context.value.is_integer());
assert(context.value.is_integer() || context.value.is_integer_real());
assert(context.value.is_positive());

// TODO: As an optimization, if `maxProperties` is set to the same number, do
// a single size equality assertion
return {make<SchemaCompilerAssertionSizeGreater>(
context,
SchemaCompilerValueUnsignedInteger{
static_cast<unsigned long>(context.value.to_integer()) - 1},
static_cast<unsigned long>(context.value.as_integer()) - 1},
type_condition(context, JSON::Type::Object),
SchemaCompilerTargetType::Instance)};
}
Expand Down

0 comments on commit d6587f0

Please sign in to comment.