Commit Graph

74 Commits

Author SHA1 Message Date
andrejlevkovitch
7554b4ca70 add checking about format-checker existance at schema parsing time 2020-06-12 17:22:46 +02:00
Patrick Boettcher
8125a3e352 after et_root_schema, throw if there are undef refs
fix #97
2020-05-15 09:35:11 +02:00
Patrick Boettcher
c12a27eee1 use schema to validate json-patch and use json_pointer to verify path
fix #107
2020-05-15 08:59:11 +02:00
Patrick Boettcher
a0fca479f6 fix #109: use weak_ptr in schema_refs 2020-05-01 11:19:16 +02:00
Patrick Boettcher
2cc7e9aaa5 schema-URIs with plain name identifiers cannot have derived sub-schema-URIs
fix #96
2020-04-25 08:26:55 +02:00
Patrick Boettcher
b28c15adea fix #101: throw an exception if JSON-type of schema is not one of the expected types 2020-04-15 09:37:16 +02:00
Patrick Boettcher
03af1b5e1e fix #100: only look for "unknown keyword" if the uri contains a pointer. 2020-04-15 09:37:04 +02:00
Patrick Boettcher
81eba4928d fix #98: catch out-of-range-exception only
Leave other exception go through - real errors.
2020-04-09 15:16:25 +02:00
Patrick Boettcher
940262ceae fix #93 by returning default-values for refs
and also return them for root-schemas
2020-03-26 10:49:58 +01:00
Sven Fink
cb95425f59 Add schema class that is aware of a default entry
Uses json patch format for defaults: json patch (RFC 6902) makes it
clearer in case of array contents. It is supported by nlohmann::json and
can be applied with `patch` to fill up the json with defaults.
2020-03-10 14:32:10 +01:00
Sven Fink
7264fa0a05 Internal root_schema may move callbacks 2020-02-11 07:30:09 +01:00
Sven Fink
d84e0a28d6 Allow create validator from rvalue json 2020-02-11 07:30:09 +01:00
Sven Fink
01e3dea71b Avoid copy of json on set_root_schema
If a json object containing a schema is moved into the json validator it
should not be copied. At least the public interface of the validator
class schould not force the copy.
2020-02-10 11:52:12 +01:00
Sven Fink
e146b37a32 Add virtual dtor to schema 2020-02-10 08:11:28 +01:00
Luke Kersting
8a7d1d3fde Adapt CMake project name to be coherent with nlohmann::json's naming
Now when json-schema-validator is installed CMake config files are installed in the lib/cmake/json-schema-validator directory.
The install json-schema-validatorTargets.cmake file properly imports the json-hpp and json-schema-validator libraries.
The install json-schema-validatorConfig.cmake file is used by CMake find_package function to include the json-schema-validatorTargets.cmake file and to set the variable JSON_SCHEMA_VALIDATOR_INCLUDE_DIRS to the install include directory.
To use find_package to find the json-schema-validator simply include.
A new test (test_cmake_install) has been added.

When NLohmann's JSON is install with CMake, it follows a certain
naming convention.

As we learned to do proper CMake-install thanks to @lkersting's work
this project now adapts to the way NLohmann is doing it. Namely:

- json-schema.hpp is now located (and installed)
  in a nlohmann/-subdirectory
- the CMake library and project's name is now
  nlohmann_json_schema_validator

Instead of doing non-standard acrobatics to find the json.hpp
now find_package is used in order to find NLohmann's package

Co-Authored-By: Patrick Boettcher <p@yai.se>
2019-12-05 11:12:23 +01:00
mxmlnkn
ad8f158284 add support for some built-in string format specifiers: date-time, date, time, ipv4, ipv6 2019-12-03 16:28:54 +01:00
Patrick Boettcher
fa978cb766 fix #76: fix compilation when there is not regex-library at all
Contributed by @mrspacemankey
2019-11-27 13:58:38 +01:00
Patrick Boettcher
49131a8713 fix #75: unknown keywords may contain sub-schemas
Now when an unknown keyword appears and its value is an object,
sub-unknown-keywords are inserted as possible sub-schemas.
2019-11-27 13:53:28 +01:00
Patrick Boettcher
e2bdcbea2d update comments 2019-11-27 13:53:23 +01:00
Patrick Boettcher
3ec0e69a0b Add support for plain-name-fragment
Plain-name-fragments are something like

    file.json#plain

plain here is not a JSON-pointer but a
Location-independent Identifier or plain-name.

Fixes #72
2019-10-23 14:46:34 +02:00
Patrick Boettcher
79639446a0 Add constructor taking a root-schema as argument
This way the validator can be used static/global loading once a root-schema.

As no try/catch-compound can be placed around, it has to be a valid schema.

Related to #70
2019-10-14 11:58:16 +02:00
Patrick Boettcher
5617eeec4e root-schema: allow re-setting a new root-schema
Fixes #70
2019-10-14 11:46:13 +02:00
Patrick Boettcher
c0d3a287d3 fix #55: make additionalProperties-error-message clearer
Done this by using sub-error-handler of type first_error_handler
and constructing a message.
2019-05-02 17:11:38 +02:00
garethsb-sony
6d5ab6cf37 Error reporting improvements
report first error message of first subschema failure for 'allOf'
make other error messages more consistent
json_validator::validate can be const
introduce error_handler 'interface'
typedefs for schema_loader and format_checker functions
remove some commented-out debugging code
2019-03-29 11:08:20 +01:00
Patrick Boettcher
4ca18cbd63 fix #54: use signed-integer-validator even for number_unsigned 2019-03-29 10:57:01 +01:00
garethsb-sony
c40fb7aa34 Improve error-message-grammar and style. 2019-03-20 15:44:14 +01:00
Patrick Boettcher
6c482e1035 error-handler now receives a json_pointer as path
Indicating where in the instance the error occurred.
The pointer is relative to the root of the instance.
2019-03-20 15:22:51 +01:00
Patrick Boettcher
746394922a Use push_back of nlohmann::json_pointer if available. 2019-03-20 14:36:07 +01:00
Patrick Boettcher
4b6330a0a8 fix format and remove unused arg-warning 2019-01-24 18:25:06 +01:00
garethsb-sony
011bd4470e Performing runtime tests on the combine_logic template argument causes "warning C4127: conditional expression is constant" from Visual Studio. Refactor so that the appropriate tests are selected at compile time. 2019-01-24 18:10:17 +01:00
garethsb-sony
a1c6531540 [#48] Tolerable difference depends on input values (and since x must be larger than multipleOf value in order to succeed, that's the critical one) 2019-01-24 18:10:17 +01:00
garethsb-sony
cf32c4e8fd [#47] Suppress "warning C4244: 'argument': conversion from '__int64' to 'double', possible loss of data" from Visual Studio 2019-01-24 18:10:17 +01:00
garethsb-sony
9dc77f7159 Avoid "warning C4457: declaration of 'e' hides function parameter" from Visual Studio and equivalent in GCC 2019-01-24 18:10:17 +01:00
garethsb-sony
c9ff2c8c4c json_validator used to be copyable; it can still be movable 2019-01-21 11:02:25 +00:00
garethsb-sony
4a9b26afce Add missing #include, to compile with VS2015 2019-01-21 11:02:25 +00:00
Patrick Boettcher
1e50a93626 Fix #44: format-checker-callback was not used, is now 2019-01-13 18:05:44 +01:00
Patrick Boettcher
7beb40bc61 Complete rewrite of the validator - aiming a 2.0-release
Schema a now "parsed" into C++-validator-objects in a first
step and then validation takes place with these objects.

Errors are now handled via a user-provided error-handler
allowing the user to collect all errors at once or bail out
when a certain threshold is reached. Fixes #36 and #8.

One (sub-)schema can now be referenced with different URIs. Fixes #9

JSON schema draft 7 is now supported. Fixes #35
2018-12-27 16:59:19 +01:00
Bryan Gillespie
2db9c1e426 Fix #28: Differentiate integer and floating point validation 2018-04-18 14:08:15 +02:00
Patrick Boettcher
a5521b4b02 numbers: do not use (unsigned) int for numbers but always double
fixes #27
2018-03-30 11:25:44 +02:00
Patrick Boettcher
5f199477d4 Fix #22: update undefined-schema set after child-schema-insertation
It can well be that a child schema is including a grand-child-schema which
is considered undefined by a parent schema. Before this fix, this failed
because when the parent schema tried to insert the child-child-schema as
child-schema it was already present. Now this is fixed by updating
the undefined references after each schema insertion.
2018-03-07 19:30:54 +01:00
Patrick Boettcher
ad9e9923ab fix message if value is too low (minimum)
A value is rather "below" a minimum than "exceeding" it
2018-02-09 10:25:08 +01:00
Ryan Ham
378105024e Change error message for "minItems".
The error message for "minItems" was the same as "maxItems". Change it to use the same verbiage as "minProperties".
2017-11-21 08:05:55 +01:00
Gert Van Hoey
42b32c500c Build as shared library on Windows using Visual Studio compiler (#10)
* Build on Windows using Visual Studio and export symbols from DLL

* Fix two warnings on raised by Visual Studio 2015 compiler + disable -Wall and -Wextra when using Visual Studio compiler

* Fix indentation (TAB instead of spaces)
2017-08-07 13:35:35 +02:00
Patrick Boettcher
dd2d95cf0a gcc-4.8: if less than 4.9 use boost::regex, if detected 2017-03-06 10:44:20 +01:00
Patrick Boettcher
46bafd05b8 regex: on gcc < 4.9 do not use std::regex
This makes that patternProperties always succeed now if gcc < 4.9
2017-02-18 13:05:45 +01:00
Patrick Boettcher
d957c9f667 compiler-warnings: use size_t as explicit type for comparisons with size_t 2017-02-01 23:41:09 +01:00
ronen barzel
e666f9f7ba add const to validate() parameter
…and propogate it everywhere
2017-02-01 11:39:39 +01:00
ronen barzel
64ca27518e Accept integer as a number in a list of types 2017-02-01 11:37:23 +01:00
ronen barzel
a071c8bdc6 use bool rather than json(bool) to avoid compiler ambiguity errors
the second value of the tuple returned by std::set.insert() is a native bool, not a json(bool).
2017-02-01 11:36:20 +01:00
ronen barzel
6cacbf197e use explicit json.get<type>() to avoid compiler ambiguity errors 2017-02-01 11:36:20 +01:00