From 4ca18cbd63873ad6f89225b50f24f6580af29786 Mon Sep 17 00:00:00 2001 From: Patrick Boettcher
Date: Fri, 29 Mar 2019 10:57:01 +0100
Subject: [PATCH] fix #54: use signed-integer-validator even for
number_unsigned
---
src/json-validator.cpp | 15 ++++++++-------
test/issue-54/CMakeLists.txt | 3 +++
test/issue-54/instance.json | 1 +
test/issue-54/schema.json | 4 ++++
4 files changed, 16 insertions(+), 7 deletions(-)
create mode 100644 test/issue-54/CMakeLists.txt
create mode 100644 test/issue-54/instance.json
create mode 100644 test/issue-54/schema.json
diff --git a/src/json-validator.cpp b/src/json-validator.cpp
index 3b60bfc..3fbc2db 100644
--- a/src/json-validator.cpp
+++ b/src/json-validator.cpp
@@ -398,7 +398,6 @@ public:
{"string", json::value_t::string},
{"boolean", json::value_t::boolean},
{"integer", json::value_t::number_integer},
- {"integer", json::value_t::number_unsigned},
{"number", json::value_t::number_float},
};
@@ -435,12 +434,14 @@ public:
for (auto &key : known_keywords)
sch.erase(key);
- // with nlohmann::json floats can be seen as unsigned or integer - reuse the number-validator for
- // integer values as well, if they have not been specified
+ // with nlohmann::json float instance (but number in schema-definition) can be seen as unsigned or integer -
+ // reuse the number-validator for integer values as well, if they have not been specified explicitly
if (type_[(uint8_t) json::value_t::number_float] && !type_[(uint8_t) json::value_t::number_integer])
- type_[(uint8_t) json::value_t::number_integer] =
- type_[(uint8_t) json::value_t::number_unsigned] =
- type_[(uint8_t) json::value_t::number_float];
+ type_[(uint8_t) json::value_t::number_integer] = type_[(uint8_t) json::value_t::number_float];
+
+ // #54: JSON-schema does not differentiate between unsigned and signed integer - nlohmann::json does
+ // we stick with JSON-schema: use the integer-validator if instance-value is unsigned
+ type_[(uint8_t) json::value_t::number_unsigned] = type_[(uint8_t) json::value_t::number_integer];
attr = sch.find("enum");
if (attr != sch.end()) {
@@ -995,8 +996,8 @@ std::shared_ptr