WIP converting all static strings over to draft 2020-12
This commit is contained in:
parent
40af3ec396
commit
a244024759
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": {
|
||||
|
||||
194
schema
194
schema
@ -1,168 +1,58 @@
|
||||
{
|
||||
"$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": []
|
||||
}
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$vocabulary": {
|
||||
"https://json-schema.org/draft/2020-12/vocab/core": true,
|
||||
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
|
||||
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
|
||||
"https://json-schema.org/draft/2020-12/vocab/validation": true,
|
||||
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
|
||||
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
|
||||
"https://json-schema.org/draft/2020-12/vocab/content": true
|
||||
},
|
||||
"$dynamicAnchor": "meta",
|
||||
|
||||
"title": "Core and Validation specifications meta-schema",
|
||||
"allOf": [
|
||||
{"$ref": "meta/core"},
|
||||
{"$ref": "meta/applicator"},
|
||||
{"$ref": "meta/unevaluated"},
|
||||
{"$ref": "meta/validation"},
|
||||
{"$ref": "meta/meta-data"},
|
||||
{"$ref": "meta/format-annotation"},
|
||||
{"$ref": "meta/content"}
|
||||
],
|
||||
"type": ["object", "boolean"],
|
||||
"$comment": "This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",
|
||||
"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": {
|
||||
"$comment": "\"definitions\" has been replaced by \"$defs\".",
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"properties": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"patternProperties": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"propertyNames": { "format": "regex" },
|
||||
"additionalProperties": { "$dynamicRef": "#meta" },
|
||||
"deprecated": true,
|
||||
"default": {}
|
||||
},
|
||||
"dependencies": {
|
||||
"$comment": "\"dependencies\" has been split and replaced by \"dependentSchemas\" and \"dependentRequired\" in order to serve their differing semantics.",
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#" },
|
||||
{ "$ref": "#/definitions/stringArray" }
|
||||
{ "$dynamicRef": "#meta" },
|
||||
{ "$ref": "meta/validation#/$defs/stringArray" }
|
||||
]
|
||||
}
|
||||
},
|
||||
"deprecated": true,
|
||||
"default": {}
|
||||
},
|
||||
"propertyNames": { "$ref": "#" },
|
||||
"const": true,
|
||||
"enum": {
|
||||
"type": "array",
|
||||
"items": true,
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
"$recursiveAnchor": {
|
||||
"$comment": "\"$recursiveAnchor\" has been replaced by \"$dynamicAnchor\".",
|
||||
"$ref": "meta/core#/$defs/anchorString",
|
||||
"deprecated": 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
|
||||
"$recursiveRef": {
|
||||
"$comment": "\"$recursiveRef\" has been replaced by \"$dynamicRef\".",
|
||||
"$ref": "meta/core#/$defs/uriReferenceString",
|
||||
"deprecated": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
target_sources(nlohmann_json_schema_validator PRIVATE
|
||||
smtp-address-validator.cpp
|
||||
json-schema-draft7.json.cpp
|
||||
json-schema-draft_2020-12.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
|
||||
75
src/json-schema-draft_2020-12.json.cpp
Normal file
75
src/json-schema-draft_2020-12.json.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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 draft_2020_12_schema_builtin = R"( {
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$vocabulary": {
|
||||
"https://json-schema.org/draft/2020-12/vocab/core": true,
|
||||
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
|
||||
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
|
||||
"https://json-schema.org/draft/2020-12/vocab/validation": true,
|
||||
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
|
||||
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
|
||||
"https://json-schema.org/draft/2020-12/vocab/content": true
|
||||
},
|
||||
"$dynamicAnchor": "meta",
|
||||
|
||||
"title": "Core and Validation specifications meta-schema",
|
||||
"allOf": [
|
||||
{"$ref": "meta/core"},
|
||||
{"$ref": "meta/applicator"},
|
||||
{"$ref": "meta/unevaluated"},
|
||||
{"$ref": "meta/validation"},
|
||||
{"$ref": "meta/meta-data"},
|
||||
{"$ref": "meta/format-annotation"},
|
||||
{"$ref": "meta/content"}
|
||||
],
|
||||
"type": ["object", "boolean"],
|
||||
"$comment": "This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",
|
||||
"properties": {
|
||||
"definitions": {
|
||||
"$comment": "\"definitions\" has been replaced by \"$defs\".",
|
||||
"type": "object",
|
||||
"additionalProperties": { "$dynamicRef": "#meta" },
|
||||
"deprecated": true,
|
||||
"default": {}
|
||||
},
|
||||
"dependencies": {
|
||||
"$comment": "\"dependencies\" has been split and replaced by \"dependentSchemas\" and \"dependentRequired\" in order to serve their differing semantics.",
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"anyOf": [
|
||||
{ "$dynamicRef": "#meta" },
|
||||
{ "$ref": "meta/validation#/$defs/stringArray" }
|
||||
]
|
||||
},
|
||||
"deprecated": true,
|
||||
"default": {}
|
||||
},
|
||||
"$recursiveAnchor": {
|
||||
"$comment": "\"$recursiveAnchor\" has been replaced by \"$dynamicAnchor\".",
|
||||
"$ref": "meta/core#/$defs/anchorString",
|
||||
"deprecated": true
|
||||
},
|
||||
"$recursiveRef": {
|
||||
"$comment": "\"$recursiveRef\" has been replaced by \"$dynamicRef\".",
|
||||
"$ref": "meta/core#/$defs/uriReferenceString",
|
||||
"deprecated": 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
|
||||
|
||||
@ -37,7 +37,7 @@ 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.
|
||||
@ -128,7 +128,7 @@ public:
|
||||
namespace json_schema
|
||||
{
|
||||
|
||||
extern json draft7_schema_builtin;
|
||||
extern json draft_2020_12_schema_builtin;
|
||||
|
||||
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 (uri.location() == "http://json-schema.org/draft/2020-12/schema") {
|
||||
schema = nlohmann::json_schema::draft_2020_12_schema_builtin;
|
||||
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"
|
||||
}
|
||||
|
||||
@ -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",
|
||||
"definitions": {
|
||||
"topDef": {
|
||||
"$id": "#topDef_ref",
|
||||
|
||||
10
test/uri.cpp
10
test/uri.cpp
@ -91,15 +91,15 @@ int main(void)
|
||||
"",
|
||||
"");
|
||||
|
||||
json_uri http("http://json-schema.org/draft-07/schema#");
|
||||
json_uri http("http://json-schema.org/draft/2020-12/schema");
|
||||
paths(http,
|
||||
"http://json-schema.org/draft-07/schema",
|
||||
"http://json-schema.org/draft-07",
|
||||
"http://json-schema.org/draft/2020-12/schema",
|
||||
"http://json-schema.org/draft/2020-12",
|
||||
"http://json-schema.org");
|
||||
|
||||
pointer_plain_name(http,
|
||||
"http://json-schema.org/draft-07/schema",
|
||||
"http://json-schema.org/draft-07",
|
||||
"http://json-schema.org/draft/2020-12/schema",
|
||||
"http://json-schema.org/draft/2020-12",
|
||||
"http://json-schema.org");
|
||||
|
||||
return errors;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user