Merge cd862228d6 into 40af3ec396
This commit is contained in:
commit
7c8fb6ed23
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
[submodule "json-schema-spec"]
|
||||
path = json-schema-spec/2020-12
|
||||
url = ../../json-schema-org/json-schema-spec.git
|
||||
[submodule "json-schema-spec_2019-09"]
|
||||
path = json-schema-spec/2019-09
|
||||
url = ../../json-schema-org/json-schema-spec.git
|
||||
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
cmake_minimum_required(VERSION 3.19)
|
||||
# CMake version compatibility
|
||||
# TODO: Remove when bumping cmake >= 3.25
|
||||
if (POLICY CMP0140)
|
||||
@ -151,6 +151,9 @@ add_subdirectory(src)
|
||||
|
||||
# Enable examples
|
||||
|
||||
# Convert meta-schema into strings and include into build
|
||||
add_subdirectory(json-schema-spec)
|
||||
|
||||
# Enable testings
|
||||
if (JSON_VALIDATOR_BUILD_TESTS)
|
||||
enable_testing()
|
||||
@ -161,7 +164,6 @@ if (JSON_VALIDATOR_BUILD_EXAMPLES)
|
||||
add_subdirectory(example)
|
||||
endif ()
|
||||
|
||||
|
||||
#[==============================================================================================[
|
||||
# Install or Export #
|
||||
]==============================================================================================]
|
||||
|
||||
10
README.md
10
README.md
@ -6,7 +6,7 @@
|
||||
|
||||
This is a C++ library for validating JSON documents based on a
|
||||
[JSON Schema](http://json-schema.org/) which itself should validate with
|
||||
[draft-7 of JSON Schema Validation](http://json-schema.org/schema).
|
||||
[draft 2020-12 of JSON Schema Validation](http://json-schema.org/schema).
|
||||
|
||||
First a disclaimer: *It is work in progress and
|
||||
contributions or hints or discussions are welcome.*
|
||||
@ -24,7 +24,7 @@ Although significant changes have been done for the 2nd version
|
||||
(a complete rewrite) the API is compatible with the 1.0.0 release. Except for
|
||||
the namespace which is now `nlohmann::json_schema`.
|
||||
|
||||
Version **2** supports JSON schema draft 7, whereas 1 was supporting draft 4
|
||||
Version **2** supports JSON schema draft 2020-12, whereas 1 was supporting draft 4
|
||||
only. Please update your schemas.
|
||||
|
||||
The primary change in 2 is the way a schema is used. While in version 1 the schema was
|
||||
@ -170,7 +170,7 @@ using nlohmann::json_schema::json_validator;
|
||||
// The schema is defined based upon a string literal
|
||||
static json person_schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"title": "A person",
|
||||
"properties": {
|
||||
"name": {
|
||||
@ -314,7 +314,7 @@ using nlohmann::json_schema::json_validator;
|
||||
|
||||
static const json rectangle_schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"title": "A rectangle",
|
||||
"properties": {
|
||||
"width": {
|
||||
@ -353,7 +353,7 @@ int main()
|
||||
|
||||
The example above will output the specified default values `{"height":10,"width":20}` to stdout.
|
||||
|
||||
> Note that the default value specified in a `$ref` may be overridden by the current instance location. Also note that this behavior will break draft-7, but it is compliant to newer drafts (e.g. `2019-09` or `2020-12`).
|
||||
> Note that the default value specified in a `$ref` may be overridden by the current instance location. Also note that this behavior will break draft 2020-12, but it is compliant to newer drafts (e.g. `2019-09` or `2020-12`).
|
||||
|
||||
# Contributing
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ using nlohmann::json_schema::json_validator;
|
||||
// The schema is defined based upon a string literal
|
||||
static json uri_schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"myUri": {
|
||||
|
||||
@ -9,7 +9,7 @@ using nlohmann::json_schema::json_validator;
|
||||
// The schema is defined based upon a string literal
|
||||
static json person_schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"title": "A person",
|
||||
"properties": {
|
||||
"name": {
|
||||
|
||||
1
json-schema-spec/2019-09
Submodule
1
json-schema-spec/2019-09
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit c8eb3d320f60eca7cfb18da25337a426ceb40eaa
|
||||
1
json-schema-spec/2020-12
Submodule
1
json-schema-spec/2020-12
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 0d2e45422eda1dd5d3eb76905cb816b612d63a5b
|
||||
44
json-schema-spec/CMakeLists.txt
Normal file
44
json-schema-spec/CMakeLists.txt
Normal file
@ -0,0 +1,44 @@
|
||||
#[==============================================================================================[
|
||||
# Meta-schema Generation #
|
||||
]==============================================================================================]
|
||||
|
||||
function (addSchemaFileToBuild META_SCHEMA_PATH)
|
||||
file(READ ${META_SCHEMA_PATH} FILE_CONTENT)
|
||||
string(JSON META_SCHEMA_ID GET ${FILE_CONTENT} "$id")
|
||||
string(REPLACE "(" "-^-(" FILE_CONTENT "${FILE_CONTENT}") # work around the reality that there may be '(' within strings
|
||||
string(REPLACE ")" ")-^-" FILE_CONTENT "${FILE_CONTENT}") # work around the reality that there may be ')' within strings
|
||||
#string(REPLACE "\n" ")\"\nR\"(" FILE_CONTENT "${FILE_CONTENT}") # break lines into separate strings so that they are not too long for VS
|
||||
set(SOURCES ${SOURCES} PARENT_SCOPE)
|
||||
file (APPEND ${SCHEMA_CPP_FILE_NAME} " {\"${META_SCHEMA_ID}\",\nR\"(")
|
||||
file (APPEND ${SCHEMA_CPP_FILE_NAME} ${FILE_CONTENT})
|
||||
file (APPEND ${SCHEMA_CPP_FILE_NAME} ")\"_json},\n")
|
||||
endfunction()
|
||||
|
||||
# this logic is such that the schema header file will only be generated once; until a "clean"
|
||||
set(SCHEMA_BASE_FILE_NAME builtin_schema_map)
|
||||
set(SCHEMA_BASE_FILE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${SCHEMA_BASE_FILE_NAME})
|
||||
set(SCHEMA_HEADER_FILE_NAME ${SCHEMA_BASE_FILE_PATH}.h)
|
||||
set(SCHEMA_CPP_FILE_NAME ${SCHEMA_BASE_FILE_PATH}.cpp)
|
||||
if (EXISTS ${SCHEMA_HEADER_FILE_NAME})
|
||||
message("Not re-generating meta schema source files")
|
||||
else()
|
||||
file (WRITE ${SCHEMA_HEADER_FILE_NAME} "#include <map>\n#include <string>\n#include <nlohmann/json.hpp>\nnamespace nlohmann {\n namespace json_schema {\n const extern std::map<std::string,json> builtin_schema_map;\n }\n}\n")
|
||||
file (WRITE ${SCHEMA_CPP_FILE_NAME} "#include \"${SCHEMA_BASE_FILE_NAME}.h\"\nnamespace nlohmann {\n namespace json_schema {\n const std::map<std::string,json> builtin_schema_map = {\n")
|
||||
file (GLOB META_SCHEMA_PATHS
|
||||
2019-09/meta/*.json
|
||||
2020-12/meta/*.json
|
||||
)
|
||||
LIST(APPEND META_SCHEMA_PATHS
|
||||
2019-09/schema.json
|
||||
2020-12/schema.json
|
||||
)
|
||||
message("META_SCHEMA_PATHS = ${META_SCHEMA_PATHS}")
|
||||
foreach(ext_json_path ${META_SCHEMA_PATHS})
|
||||
addSchemaFileToBuild(${ext_json_path} APPEND) # subsequent invocations of addSchemaFileToBuild(), use APPEND
|
||||
endforeach()
|
||||
file (APPEND ${SCHEMA_CPP_FILE_NAME} " };\n }\n}\n")
|
||||
endif()
|
||||
|
||||
target_sources(nlohmann_json_schema_validator PRIVATE ${SCHEMA_CPP_FILE_NAME})
|
||||
target_include_directories(nlohmann_json_schema_validator PRIVATE ${CMAKE_BINARY_DIR}/json-schema-spec)
|
||||
|
||||
11
json-schema-spec/README.md
Normal file
11
json-schema-spec/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
# JSON Schema Spec
|
||||
|
||||
This directory contains several dialects of the JSON, also known
|
||||
as meta-schema.
|
||||
This is done using git submodules, so that the upstream version
|
||||
can be tracked and updated easily.
|
||||
|
||||
The `2019-09` dialect is not really supported, nor is it intended
|
||||
to be.
|
||||
However, it is included here as an example of how multiple dialects
|
||||
will be supported, looking forward to the next release.
|
||||
168
schema
168
schema
@ -1,168 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$id": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Core schema meta-schema",
|
||||
"definitions": {
|
||||
"schemaArray": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": { "$ref": "#" }
|
||||
},
|
||||
"nonNegativeInteger": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"nonNegativeIntegerDefault0": {
|
||||
"allOf": [
|
||||
{ "$ref": "#/definitions/nonNegativeInteger" },
|
||||
{ "default": 0 }
|
||||
]
|
||||
},
|
||||
"simpleTypes": {
|
||||
"enum": [
|
||||
"array",
|
||||
"boolean",
|
||||
"integer",
|
||||
"null",
|
||||
"number",
|
||||
"object",
|
||||
"string"
|
||||
]
|
||||
},
|
||||
"stringArray": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" },
|
||||
"uniqueItems": true,
|
||||
"default": []
|
||||
}
|
||||
},
|
||||
"type": ["object", "boolean"],
|
||||
"properties": {
|
||||
"$id": {
|
||||
"type": "string",
|
||||
"format": "uri-reference"
|
||||
},
|
||||
"$schema": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
},
|
||||
"$ref": {
|
||||
"type": "string",
|
||||
"format": "uri-reference"
|
||||
},
|
||||
"$comment": {
|
||||
"type": "string"
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": true,
|
||||
"readOnly": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"examples": {
|
||||
"type": "array",
|
||||
"items": true
|
||||
},
|
||||
"multipleOf": {
|
||||
"type": "number",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"maximum": {
|
||||
"type": "number"
|
||||
},
|
||||
"exclusiveMaximum": {
|
||||
"type": "number"
|
||||
},
|
||||
"minimum": {
|
||||
"type": "number"
|
||||
},
|
||||
"exclusiveMinimum": {
|
||||
"type": "number"
|
||||
},
|
||||
"maxLength": { "$ref": "#/definitions/nonNegativeInteger" },
|
||||
"minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
|
||||
"pattern": {
|
||||
"type": "string",
|
||||
"format": "regex"
|
||||
},
|
||||
"additionalItems": { "$ref": "#" },
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#" },
|
||||
{ "$ref": "#/definitions/schemaArray" }
|
||||
],
|
||||
"default": true
|
||||
},
|
||||
"maxItems": { "$ref": "#/definitions/nonNegativeInteger" },
|
||||
"minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
|
||||
"uniqueItems": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"contains": { "$ref": "#" },
|
||||
"maxProperties": { "$ref": "#/definitions/nonNegativeInteger" },
|
||||
"minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
|
||||
"required": { "$ref": "#/definitions/stringArray" },
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"definitions": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"properties": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"patternProperties": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"propertyNames": { "format": "regex" },
|
||||
"default": {}
|
||||
},
|
||||
"dependencies": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#" },
|
||||
{ "$ref": "#/definitions/stringArray" }
|
||||
]
|
||||
}
|
||||
},
|
||||
"propertyNames": { "$ref": "#" },
|
||||
"const": true,
|
||||
"enum": {
|
||||
"type": "array",
|
||||
"items": true,
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"type": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#/definitions/simpleTypes" },
|
||||
{
|
||||
"type": "array",
|
||||
"items": { "$ref": "#/definitions/simpleTypes" },
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"format": { "type": "string" },
|
||||
"contentMediaType": { "type": "string" },
|
||||
"contentEncoding": { "type": "string" },
|
||||
"if": {"$ref": "#"},
|
||||
"then": {"$ref": "#"},
|
||||
"else": {"$ref": "#"},
|
||||
"allOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"anyOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"oneOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"not": { "$ref": "#" }
|
||||
},
|
||||
"default": true
|
||||
}
|
||||
@ -1,6 +1,5 @@
|
||||
target_sources(nlohmann_json_schema_validator PRIVATE
|
||||
smtp-address-validator.cpp
|
||||
json-schema-draft7.json.cpp
|
||||
json-uri.cpp
|
||||
json-validator.cpp
|
||||
json-patch.cpp
|
||||
|
||||
@ -9,7 +9,7 @@ namespace
|
||||
// with fixes
|
||||
const nlohmann::json patch_schema = R"patch({
|
||||
"title": "JSON schema for JSONPatch files",
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"type": "array",
|
||||
|
||||
"items": {
|
||||
|
||||
@ -1,185 +0,0 @@
|
||||
/*
|
||||
* JSON schema validator for JSON for modern C++
|
||||
*
|
||||
* Copyright (c) 2016-2019 Patrick Boettcher <p@yai.se>.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
namespace json_schema
|
||||
{
|
||||
|
||||
json draft7_schema_builtin = R"( {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$id": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Core schema meta-schema",
|
||||
"definitions": {
|
||||
"schemaArray": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": { "$ref": "#" }
|
||||
},
|
||||
"nonNegativeInteger": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"nonNegativeIntegerDefault0": {
|
||||
"allOf": [
|
||||
{ "$ref": "#/definitions/nonNegativeInteger" },
|
||||
{ "default": 0 }
|
||||
]
|
||||
},
|
||||
"simpleTypes": {
|
||||
"enum": [
|
||||
"array",
|
||||
"boolean",
|
||||
"integer",
|
||||
"null",
|
||||
"number",
|
||||
"object",
|
||||
"string"
|
||||
]
|
||||
},
|
||||
"stringArray": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" },
|
||||
"uniqueItems": true,
|
||||
"default": []
|
||||
}
|
||||
},
|
||||
"type": ["object", "boolean"],
|
||||
"properties": {
|
||||
"$id": {
|
||||
"type": "string",
|
||||
"format": "uri-reference"
|
||||
},
|
||||
"$schema": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
},
|
||||
"$ref": {
|
||||
"type": "string",
|
||||
"format": "uri-reference"
|
||||
},
|
||||
"$comment": {
|
||||
"type": "string"
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": true,
|
||||
"readOnly": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"examples": {
|
||||
"type": "array",
|
||||
"items": true
|
||||
},
|
||||
"multipleOf": {
|
||||
"type": "number",
|
||||
"exclusiveMinimum": 0
|
||||
},
|
||||
"maximum": {
|
||||
"type": "number"
|
||||
},
|
||||
"exclusiveMaximum": {
|
||||
"type": "number"
|
||||
},
|
||||
"minimum": {
|
||||
"type": "number"
|
||||
},
|
||||
"exclusiveMinimum": {
|
||||
"type": "number"
|
||||
},
|
||||
"maxLength": { "$ref": "#/definitions/nonNegativeInteger" },
|
||||
"minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
|
||||
"pattern": {
|
||||
"type": "string",
|
||||
"format": "regex"
|
||||
},
|
||||
"additionalItems": { "$ref": "#" },
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#" },
|
||||
{ "$ref": "#/definitions/schemaArray" }
|
||||
],
|
||||
"default": true
|
||||
},
|
||||
"maxItems": { "$ref": "#/definitions/nonNegativeInteger" },
|
||||
"minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
|
||||
"uniqueItems": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"contains": { "$ref": "#" },
|
||||
"maxProperties": { "$ref": "#/definitions/nonNegativeInteger" },
|
||||
"minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
|
||||
"required": { "$ref": "#/definitions/stringArray" },
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"definitions": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"properties": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"patternProperties": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"propertyNames": { "format": "regex" },
|
||||
"default": {}
|
||||
},
|
||||
"dependencies": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#" },
|
||||
{ "$ref": "#/definitions/stringArray" }
|
||||
]
|
||||
}
|
||||
},
|
||||
"propertyNames": { "$ref": "#" },
|
||||
"const": true,
|
||||
"enum": {
|
||||
"type": "array",
|
||||
"items": true,
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"type": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#/definitions/simpleTypes" },
|
||||
{
|
||||
"type": "array",
|
||||
"items": { "$ref": "#/definitions/simpleTypes" },
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"format": { "type": "string" },
|
||||
"contentMediaType": { "type": "string" },
|
||||
"contentEncoding": { "type": "string" },
|
||||
"if": { "$ref": "#" },
|
||||
"then": { "$ref": "#" },
|
||||
"else": { "$ref": "#" },
|
||||
"allOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"anyOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"oneOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"not": { "$ref": "#" }
|
||||
},
|
||||
"default": true
|
||||
} )"_json;
|
||||
}
|
||||
} // namespace nlohmann
|
||||
@ -1409,7 +1409,7 @@ std::shared_ptr<schema> schema::make(json &schema,
|
||||
|
||||
schema.erase(attr);
|
||||
|
||||
// special case where we break draft-7 and allow overriding of properties when a $ref is used
|
||||
// special case where we break draft-7 and allow overriding of properties when a $ref is used <<-- might be out-of-date now that 2020-12 is used
|
||||
attr = schema.find("default");
|
||||
if (attr != schema.end()) {
|
||||
// copy the referenced schema depending on the underlying type and modify the default value
|
||||
|
||||
@ -31,13 +31,15 @@
|
||||
# error "expected existing NLOHMANN_JSON_VERSION_MAJOR preproc variable, please update to NLohmann's JSON 3.8.0"
|
||||
#endif
|
||||
|
||||
//#include "builtin_schema_map.h"
|
||||
|
||||
// make yourself a home - welcome to nlohmann's namespace
|
||||
namespace nlohmann
|
||||
{
|
||||
|
||||
// A class representing a JSON-URI for schemas derived from
|
||||
// section 8 of JSON Schema: A Media Type for Describing JSON Documents
|
||||
// draft-wright-json-schema-00
|
||||
// draft-wright-json-schema-00 <<-- might be incorrect now that 2020-12 is used
|
||||
//
|
||||
// New URIs can be derived from it using the derive()-method.
|
||||
// This is useful for resolving refs or subschema-IDs in json-schemas.
|
||||
@ -127,8 +129,7 @@ public:
|
||||
|
||||
namespace json_schema
|
||||
{
|
||||
|
||||
extern json draft7_schema_builtin;
|
||||
const extern std::map<std::string,json> builtin_schema_map;
|
||||
|
||||
typedef std::function<void(const json_uri & /*id*/, json & /*value*/)> schema_loader;
|
||||
typedef std::function<void(const std::string & /*format*/, const std::string & /*value*/)> format_checker;
|
||||
|
||||
@ -398,7 +398,7 @@ void default_string_format_check(const std::string &format, const std::string &v
|
||||
throw exception;
|
||||
}
|
||||
} else {
|
||||
/* yet unsupported JSON schema draft 7 built-ins */
|
||||
/* as-of-yet unsupported JSON schema draft 2020-12 built-ins */
|
||||
static const std::vector<std::string> jsonSchemaStringFormatBuiltIns{
|
||||
"date-time", "time", "date", "email", "idn-email", "hostname", "idn-hostname", "ipv4", "ipv6", "uri",
|
||||
"uri-reference", "iri", "iri-reference", "uri-template", "json-pointer", "relative-json-pointer", "regex"};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
set(JSON_SCHEMA_TEST_PREFIX "JSON-Suite" CACHE STRING "prefix for JSON-tests added to ctest")
|
||||
|
||||
set(DRAFT "draft7")
|
||||
set(DRAFT "draft_2020-12")
|
||||
|
||||
# find schema-test-suite
|
||||
find_path(JSON_SCHEMA_TEST_SUITE_PATH
|
||||
|
||||
@ -18,8 +18,8 @@ using nlohmann::json_schema::json_validator;
|
||||
|
||||
static void loader(const json_uri &uri, json &schema)
|
||||
{
|
||||
if (uri.location() == "http://json-schema.org/draft-07/schema") {
|
||||
schema = nlohmann::json_schema::draft7_schema_builtin;
|
||||
if (nlohmann::json_schema::builtin_schema_map.count(uri.location()) > 0) {
|
||||
schema = nlohmann::json_schema::builtin_schema_map.at(uri.location());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
[
|
||||
{
|
||||
"description": "validate definition against metaschema",
|
||||
"schema": {"$ref": "http://json-schema.org/draft-07/schema#"},
|
||||
"schema": {"$schema": "http://json-schema.org/draft/2020-12/schema"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "valid definition schema",
|
||||
"data": {
|
||||
"definitions": {
|
||||
"$defs": {
|
||||
"foo": {"type": "integer"}
|
||||
}
|
||||
},
|
||||
@ -15,7 +15,7 @@
|
||||
{
|
||||
"description": "invalid definition schema",
|
||||
"data": {
|
||||
"definitions": {
|
||||
"$defs": {
|
||||
"foo": {"type": 1}
|
||||
}
|
||||
},
|
||||
@ -213,7 +213,7 @@
|
||||
},
|
||||
{
|
||||
"description": "remote ref, containing refs itself",
|
||||
"schema": {"$ref": "http://json-schema.org/draft-07/schema#"},
|
||||
"schema": {"$schema": "https://json-schema.org/draft/2020-12/schema"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "remote ref valid",
|
||||
@ -21,7 +21,7 @@ namespace
|
||||
// The schema is defined based upon a string literal
|
||||
static json person_schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"title": "A person",
|
||||
"properties": {
|
||||
"name": {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$id": "http://xxx.local/schemas/mySchema.json",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$id": "http://xxx.local/schemas/mySchema.json",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"properties": {
|
||||
"x": {
|
||||
"type": "integer",
|
||||
|
||||
@ -21,7 +21,7 @@ static int error_count;
|
||||
// The schema is defined based upon a string literal
|
||||
static json person_schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"type": "integer",
|
||||
"definitions": {
|
||||
"A": {
|
||||
|
||||
@ -7,7 +7,7 @@ using nlohmann::json_schema::json_validator;
|
||||
|
||||
static const json rectangle_schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"properties": {
|
||||
"width": {
|
||||
"$ref": "#/definitions/length",
|
||||
@ -27,7 +27,7 @@ static const json rectangle_schema = R"(
|
||||
|
||||
static const json quad_schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"properties": {
|
||||
"width": {
|
||||
"$ref": "#/properties/height",
|
||||
@ -57,7 +57,7 @@ static const json quad_schema = R"(
|
||||
|
||||
static const json default_schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"definitions": {
|
||||
"defaultLength": {
|
||||
"default": 5
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://example.invalid/color.schema.json",
|
||||
"title": "color",
|
||||
"description": "X11/HTML/CSS color name as a JSON string",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://example.invalid/entities.schema.json",
|
||||
"title": "Entities",
|
||||
"type": "array",
|
||||
|
||||
@ -7,7 +7,7 @@ using nlohmann::json_schema::json_validator;
|
||||
|
||||
static const json default_schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"oneOf": [
|
||||
{
|
||||
|
||||
@ -7,7 +7,7 @@ using nlohmann::json_schema::json_validator;
|
||||
|
||||
static const json root_default = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"properties": {
|
||||
"width": {
|
||||
"type": "integer"
|
||||
|
||||
@ -6,7 +6,7 @@ using nlohmann::json_schema::json_validator;
|
||||
|
||||
static const json person_schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"title": "A person",
|
||||
"properties": {
|
||||
"name": {
|
||||
|
||||
@ -6,7 +6,7 @@ using nlohmann::json_schema::json_validator;
|
||||
|
||||
static const json schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "arc.schema.json",
|
||||
"properties": {
|
||||
"angle": {
|
||||
|
||||
@ -21,7 +21,7 @@ namespace
|
||||
// The schema is defined based upon a string literal
|
||||
static json person_schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"title": "A person",
|
||||
"properties": {
|
||||
"name": {
|
||||
|
||||
@ -5,7 +5,7 @@ using nlohmann::json_schema::json_validator;
|
||||
|
||||
static const json person_schema = R"(
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"title": "A person",
|
||||
"properties": {
|
||||
"name": {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"description": "Describes bar",
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"description": "Describes foo",
|
||||
"type": "object",
|
||||
"allOf": [
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"description": "Describes baz",
|
||||
"$ref": "qux/qux.json"
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"description": "Describes qux",
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"$schema": "http://json-schema.org/draft/2020-12/schema",
|
||||
"description": "Describes foo",
|
||||
"$ref": "baz/baz.json"
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user