test(jsonschema): add json schema test suite compat tests

Add comprehensive integration tests using the official JSON-Schema-Test-Suite
draft2020-12 examples to ensure the CLI handles all valid JSON Schema constructs
without crashing.

Changes:
- Add 80 fixture files from JSON-Schema-Test-Suite draft2020-12
- Add parallelized integration test that runs CLI against all 448 schemas
- Normalize non-standard $ref patterns (root refs, JSON pointers, external URIs)
- Decode URL-encoded and JSON pointer escaped characters in $ref paths
- Embed type usages directly in $defs to avoid Tera lookup issues with
  special characters in definition names
- Handle missing $defs gracefully in template rendering

The test suite runs in ~5 seconds using Rayon for parallel execution.
This commit is contained in:
LGUG2Z committed 2025-12-22 10:04:47 -08:00
1 parent 25b4a8fae9
commit 2e3913c325
89 files changed
+17262 -18

No files matched your search

+1
View File
@@ -1 +1,2 @@
/target
/tests/outputs
Generated
+1
View File
@@ -1223,6 +1223,7 @@ dependencies = [
"clap",
"lightningcss",
"pulldown-cmark",
"rayon",
"regex",
"schemars",
"serde",
+1
View File
@@ -30,3 +30,4 @@ serde = { version = "1", features = ["derive"] }
[dev-dependencies]
regex = "1"
rayon = "1"
+11 -5
View File
@@ -111,7 +111,8 @@
{
"type": "null"
}
]
],
"deprecated": true
},
"cross_boundary_behaviour": {
"description": "Determine what happens when an action is called on a window at a monitor boundary (default: Monitor)",
@@ -245,7 +246,8 @@
{
"type": "null"
}
]
],
"deprecated": true
},
"global_work_area_offset": {
"description": "Global work area (space used for tiling) offset (default: None)",
@@ -277,7 +279,8 @@
{
"type": "null"
}
]
],
"deprecated": true
},
"layered_applications": {
"description": "Identify applications that have the WS_EX_LAYERED extended window style",
@@ -1289,7 +1292,8 @@
{
"description": "END OF LIFE FEATURE: Use the SW_HIDE flag to hide windows when switching workspaces (has issues with Electron apps)",
"type": "string",
"const": "Hide"
"const": "Hide",
"deprecated": true
},
{
"description": "Use the SW_MINIMIZE flag to hide windows when switching workspaces (has issues with frequent workspace switching)",
@@ -2384,7 +2388,8 @@
{
"type": "null"
}
]
],
"deprecated": true
},
"custom_layout_rules": {
"description": "END OF LIFE FEATURE: Custom layout rules (default: None)",
@@ -2393,6 +2398,7 @@
"null"
],
"additionalProperties": false,
"deprecated": true,
"patternProperties": {
"^\\d+$": {
"type": "string"
+5 -1
View File
@@ -7,6 +7,7 @@ use crate::identifiers::IDS;
use crate::identifiers::TYPE_CLASSES;
use crate::prepare::NavigationData;
use crate::prepare::build_navigation;
use crate::prepare::embed_usages_in_defs;
use crate::prepare::prepare_for_template;
use crate::prepare::render_markdown;
use crate::prepare::strip_markdown;
@@ -37,11 +38,14 @@ impl Generator {
/// Generate HTML documentation from a schema
pub fn generate(&self, schema: &Schema, options: &Options) -> Result<String, Error> {
// Prepare the schema for template rendering
let prepared_schema = prepare_for_template(schema.as_value());
let mut prepared_schema = prepare_for_template(schema.as_value());
// Build navigation data from the prepared schema (includes _display_name for wrapper types)
let navigation = build_navigation(&prepared_schema);
// Embed usages directly into $defs to avoid Tera lookup issues with special characters
embed_usages_in_defs(&mut prepared_schema, &navigation.usages);
// Build the template context
let context = self.build_context(&prepared_schema, &navigation, options)?;
+205 -1
View File
@@ -18,10 +18,13 @@ use std::collections::HashSet;
/// This function:
/// 1. Clones the schema value
/// 2. Recursively renders all `description` fields as markdown to `description_html`
/// 3. Returns the modified value ready for Tera
/// 3. Normalizes non-$defs refs to prevent template errors
/// 4. Returns the modified value ready for Tera
pub fn prepare_for_template(value: &Value) -> Value {
let mut prepared = value.clone();
process_value(&mut prepared);
let root_schema = prepared.clone();
normalize_refs(&mut prepared, &root_schema);
detect_wrapper_types(&mut prepared);
add_wrapper_display_names(&mut prepared);
prepared
@@ -51,6 +54,207 @@ fn add_wrapper_display_names(schema: &mut Value) {
}
}
/// Embed usages directly into each $defs entry
///
/// This avoids Tera template lookup issues with special characters in def names
/// (like quotes or empty strings). Each definition will have `_usages` with
/// `config_usages` and `type_references` arrays.
pub fn embed_usages_in_defs(schema: &mut Value, usages: &HashMap<String, TypeUsages>) {
if let Some(defs) = schema.get_mut("$defs").and_then(|v| v.as_object_mut()) {
for (name, def) in defs.iter_mut() {
if let Some(obj) = def.as_object_mut()
&& let Some(type_usages) = usages.get(name)
{
obj.insert(
"_usages".to_string(),
serde_json::to_value(type_usages).unwrap_or(Value::Null),
);
}
}
}
}
/// Normalize $ref values that don't follow the #/$defs/TypeName pattern
///
/// The template expects all $refs to be in the format #/$defs/TypeName.
/// This function handles other ref patterns:
/// - `#` (root ref): Replaces with the root schema inline
/// - `#/properties/foo` (JSON pointer): Resolves to the target or marks as unresolved
/// - `#/$defs/percent%25field` (URL-encoded): Decodes to the actual $defs name
/// - External URIs: Marks as unresolved reference
fn normalize_refs(value: &mut Value, root_schema: &Value) {
normalize_refs_recursive(value, root_schema);
}
fn normalize_refs_recursive(value: &mut Value, root_schema: &Value) {
match value {
Value::Object(map) => {
// Check if this object has a $ref that needs normalization
if let Some(ref_value) = map.get("$ref").cloned()
&& let Some(ref_str) = ref_value.as_str()
&& let Some(normalized) = normalize_single_ref(ref_str, root_schema)
{
// Replace this object with the resolved schema
// But preserve any sibling properties (like description)
if let Value::Object(resolved_map) = normalized {
// Merge: keep original properties, add resolved ones
let original_ref = map.remove("$ref");
for (k, v) in resolved_map {
if !map.contains_key(&k) {
map.insert(k, v);
}
}
// If we couldn't resolve, restore the ref but mark it
if (map.is_empty()
|| (!map.contains_key("type")
&& !map.contains_key("anyOf")
&& !map.contains_key("oneOf")
&& !map.contains_key("allOf")
&& !map.contains_key("properties")
&& !map.contains_key("enum")
&& !map.contains_key("const")))
&& let Some(orig) = original_ref
{
map.insert("$ref".to_string(), orig);
}
}
}
// Recurse into all nested values
for v in map.values_mut() {
normalize_refs_recursive(v, root_schema);
}
}
Value::Array(arr) => {
for v in arr.iter_mut() {
normalize_refs_recursive(v, root_schema);
}
}
_ => {}
}
}
/// Normalize a single $ref string, returning the resolved schema if needed
fn normalize_single_ref(ref_str: &str, root_schema: &Value) -> Option<Value> {
// Already in expected format - decode URL-encoded characters for $defs lookup
if let Some(encoded_name) = ref_str.strip_prefix("#/$defs/") {
// Skip "#/$defs/"
// Decode JSON pointer escapes: ~1 -> /, ~0 -> ~
let decoded = encoded_name.replace("~1", "/").replace("~0", "~");
// Decode URL-encoded characters: %25 -> %, etc.
let decoded = percent_decode(&decoded);
// If the decoded name differs from encoded, update the ref
if decoded != encoded_name {
// Check if the decoded name exists in $defs
if let Some(defs) = root_schema.get("$defs").and_then(|v| v.as_object())
&& defs.contains_key(&decoded)
{
return Some(serde_json::json!({
"$ref": format!("#/$defs/{}", decoded)
}));
}
}
return None; // No change needed
}
// Root reference: #
if ref_str == "#" {
// Return a placeholder type - we can't inline the whole root
return Some(serde_json::json!({
"type": "object",
"description": "(recursive reference to root schema)"
}));
}
// JSON pointer reference: #/properties/foo, #/items, etc.
if ref_str.starts_with("#/") {
if let Some(resolved) = resolve_json_pointer(ref_str, root_schema) {
return Some(resolved.clone());
}
// Couldn't resolve - return a placeholder
return Some(serde_json::json!({
"description": format!("(unresolved reference: {})", ref_str)
}));
}
// External URI reference (http://, https://, urn:, file://, etc.)
if ref_str.contains("://") || ref_str.starts_with("urn:") {
return Some(serde_json::json!({
"description": format!("(external reference: {})", ref_str)
}));
}
// Relative URI reference (e.g., "other-schema.json#/$defs/Foo")
if ref_str.contains('#') || ref_str.ends_with(".json") {
return Some(serde_json::json!({
"description": format!("(external reference: {})", ref_str)
}));
}
None // Unknown format, leave as-is
}
/// Decode percent-encoded characters in a string
fn percent_decode(s: &str) -> String {
let mut result = String::with_capacity(s.len());
let mut chars = s.chars().peekable();
while let Some(c) = chars.next() {
if c == '%' {
// Try to read two hex digits
let hex: String = chars.by_ref().take(2).collect();
if hex.len() == 2
&& let Ok(byte) = u8::from_str_radix(&hex, 16)
{
result.push(byte as char);
continue;
}
// If decoding failed, keep the original
result.push('%');
result.push_str(&hex);
} else {
result.push(c);
}
}
result
}
/// Resolve a JSON pointer within the schema
fn resolve_json_pointer<'a>(pointer: &str, schema: &'a Value) -> Option<&'a Value> {
// Remove leading #
let pointer = pointer.strip_prefix('#')?;
if pointer.is_empty() {
return Some(schema);
}
// Remove leading /
let pointer = pointer.strip_prefix('/')?;
let mut current = schema;
for segment in pointer.split('/') {
// Decode JSON pointer escapes
let decoded = segment.replace("~1", "/").replace("~0", "~");
// Also decode percent-encoding
let decoded = percent_decode(&decoded);
current = match current {
Value::Object(map) => map.get(&decoded)?,
Value::Array(arr) => {
let index: usize = decoded.parse().ok()?;
arr.get(index)?
}
_ => return None,
};
}
Some(current)
}
/// Recursively process a value, rendering markdown descriptions
fn process_value(value: &mut Value) {
match value {
+9 -8
View File
@@ -106,16 +106,17 @@
{{ def.description_html | safe }}
</div>
{% endif -%} {{ macros::render_schema(node=def, depth=0,
path=def_name) }} {# Usages section at bottom #} {%- set
type_usages = usages[def_name] -%} {%- if type_usages
and (type_usages.config_usages | length > 0 or
type_usages.type_references | length > 0) -%}
path=def_name) }} {# Usages section at bottom - use
embedded _usages to avoid lookup issues with special
chars #} {%- if def._usages and
(def._usages.config_usages | length > 0 or
def._usages.type_references | length > 0) -%}
<div class="{{ css.usages }}">
{%- if type_usages.config_usages | length > 0 -%}
{%- if def._usages.config_usages | length > 0 -%}
<div class="{{ css.usage_section }}">
<h4>Configuration Usage</h4>
<ul class="{{ css.usage_list }}">
{%- for usage in type_usages.config_usages
{%- for usage in def._usages.config_usages
-%}
<li>
<a href="#{{ usage.anchor }}"
@@ -125,12 +126,12 @@
{%- endfor -%}
</ul>
</div>
{%- endif -%} {%- if type_usages.type_references |
{%- endif -%} {%- if def._usages.type_references |
length > 0 -%}
<div class="{{ css.usage_section }}">
<h4>Referenced by</h4>
<ul class="{{ css.usage_list }}">
{%- for ref in type_usages.type_references
{%- for ref in def._usages.type_references
-%} {%- set ref_display =
display_names[ref.type_name] |
default(value=ref.type_name) -%}
+7 -3
View File
@@ -46,9 +46,13 @@
{%- if node["$ref"] -%}
{%- set ref_name = node["$ref"] | replace(from="#/$defs/", to="") -%}
{%- set display = display_names[ref_name] | default(value=ref_name) -%}
{%- set ref_def = schema["$defs"][ref_name] -%}
<a href="#{{ ref_name | lower }}" class="{{ css.type_ref }}">{{ display }}</a>
{%- if ref_def._wrapper_inner %} {{ self::render_type_badge(node=ref_def._wrapper_inner) }}{%- endif -%}
{%- if schema["$defs"][ref_name] -%}
{%- set ref_def = schema["$defs"][ref_name] -%}
<a href="#{{ ref_name | lower }}" class="{{ css.type_ref }}">{{ display }}</a>
{%- if ref_def._wrapper_inner %} {{ self::render_type_badge(node=ref_def._wrapper_inner) }}{%- endif -%}
{%- else -%}
<span class="{{ css.type_badge }} {{ type_classes.object }}">$ref</span>
{%- endif -%}
{%- elif node.type -%}
{%- if node.type is string -%}
{%- if node.type == "array" and node.prefixItems -%}
@@ -0,0 +1,219 @@
[
{
"description":
"additionalProperties being false does not allow other properties",
"specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema. Boolean \"false\" forbids everything." } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {"foo": {}, "bar": {}},
"patternProperties": { "^v": {} },
"additionalProperties": false
},
"tests": [
{
"description": "no additional properties is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "an additional property is invalid",
"data": {"foo" : 1, "bar" : 2, "quux" : "boom"},
"valid": false
},
{
"description": "ignores arrays",
"data": [1, 2, 3],
"valid": true
},
{
"description": "ignores strings",
"data": "foobarbaz",
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
},
{
"description": "patternProperties are not additional properties",
"data": {"foo":1, "vroom": 2},
"valid": true
}
]
},
{
"description": "non-ASCII pattern with additionalProperties",
"specification": [ { "core":"10.3.2.3"} ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"patternProperties": {"^á": {}},
"additionalProperties": false
},
"tests": [
{
"description": "matching the pattern is valid",
"data": {"ármányos": 2},
"valid": true
},
{
"description": "not matching the pattern is invalid",
"data": {"élmény": 2},
"valid": false
}
]
},
{
"description": "additionalProperties with schema",
"specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema." } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {"foo": {}, "bar": {}},
"additionalProperties": {"type": "boolean"}
},
"tests": [
{
"description": "no additional properties is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "an additional valid property is valid",
"data": {"foo" : 1, "bar" : 2, "quux" : true},
"valid": true
},
{
"description": "an additional invalid property is invalid",
"data": {"foo" : 1, "bar" : 2, "quux" : 12},
"valid": false
}
]
},
{
"description": "additionalProperties can exist by itself",
"specification": [ { "core":"10.3.2.3", "quote": "With no other applicator applying to object instances. This validates all the instance values irrespective of their property names" } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": {"type": "boolean"}
},
"tests": [
{
"description": "an additional valid property is valid",
"data": {"foo" : true},
"valid": true
},
{
"description": "an additional invalid property is invalid",
"data": {"foo" : 1},
"valid": false
}
]
},
{
"description": "additionalProperties are allowed by default",
"specification": [ { "core":"10.3.2.3", "quote": "Omitting this keyword has the same assertion behavior as an empty schema." } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {"foo": {}, "bar": {}}
},
"tests": [
{
"description": "additional properties are allowed",
"data": {"foo": 1, "bar": 2, "quux": true},
"valid": true
}
]
},
{
"description": "additionalProperties does not look in applicators",
"specification":[ { "core": "10.2", "quote": "Subschemas of applicator keywords evaluate the instance completely independently such that the results of one such subschema MUST NOT impact the results of sibling subschemas." } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{"properties": {"foo": {}}}
],
"additionalProperties": {"type": "boolean"}
},
"tests": [
{
"description": "properties defined in allOf are not examined",
"data": {"foo": 1, "bar": true},
"valid": false
}
]
},
{
"description": "additionalProperties with null valued instance properties",
"specification": [ { "core":"10.3.2.3" } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": {
"type": "null"
}
},
"tests": [
{
"description": "allows null values",
"data": {"foo": null},
"valid": true
}
]
},
{
"description": "additionalProperties with propertyNames",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"propertyNames": {
"maxLength": 5
},
"additionalProperties": {
"type": "number"
}
},
"tests": [
{
"description": "Valid against both keywords",
"data": { "apple": 4 },
"valid": true
},
{
"description": "Valid against propertyNames, but not additionalProperties",
"data": { "fig": 2, "pear": "available" },
"valid": false
}
]
},
{
"description": "dependentSchemas with additionalProperties",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {"foo2": {}},
"dependentSchemas": {
"foo" : {},
"foo2": {
"properties": {
"bar": {}
}
}
},
"additionalProperties": false
},
"tests": [
{
"description": "additionalProperties doesn't consider dependentSchemas",
"data": {"foo": ""},
"valid": false
},
{
"description": "additionalProperties can't see bar",
"data": {"bar": ""},
"valid": false
},
{
"description": "additionalProperties can't see bar even when foo2 is present",
"data": {"foo2": "", "bar": ""},
"valid": false
}
]
}
]
@@ -0,0 +1,312 @@
[
{
"description": "allOf",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{
"properties": {
"bar": {"type": "integer"}
},
"required": ["bar"]
},
{
"properties": {
"foo": {"type": "string"}
},
"required": ["foo"]
}
]
},
"tests": [
{
"description": "allOf",
"data": {"foo": "baz", "bar": 2},
"valid": true
},
{
"description": "mismatch second",
"data": {"foo": "baz"},
"valid": false
},
{
"description": "mismatch first",
"data": {"bar": 2},
"valid": false
},
{
"description": "wrong type",
"data": {"foo": "baz", "bar": "quux"},
"valid": false
}
]
},
{
"description": "allOf with base schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {"bar": {"type": "integer"}},
"required": ["bar"],
"allOf" : [
{
"properties": {
"foo": {"type": "string"}
},
"required": ["foo"]
},
{
"properties": {
"baz": {"type": "null"}
},
"required": ["baz"]
}
]
},
"tests": [
{
"description": "valid",
"data": {"foo": "quux", "bar": 2, "baz": null},
"valid": true
},
{
"description": "mismatch base schema",
"data": {"foo": "quux", "baz": null},
"valid": false
},
{
"description": "mismatch first allOf",
"data": {"bar": 2, "baz": null},
"valid": false
},
{
"description": "mismatch second allOf",
"data": {"foo": "quux", "bar": 2},
"valid": false
},
{
"description": "mismatch both",
"data": {"bar": 2},
"valid": false
}
]
},
{
"description": "allOf simple types",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{"maximum": 30},
{"minimum": 20}
]
},
"tests": [
{
"description": "valid",
"data": 25,
"valid": true
},
{
"description": "mismatch one",
"data": 35,
"valid": false
}
]
},
{
"description": "allOf with boolean schemas, all true",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [true, true]
},
"tests": [
{
"description": "any value is valid",
"data": "foo",
"valid": true
}
]
},
{
"description": "allOf with boolean schemas, some false",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [true, false]
},
"tests": [
{
"description": "any value is invalid",
"data": "foo",
"valid": false
}
]
},
{
"description": "allOf with boolean schemas, all false",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [false, false]
},
"tests": [
{
"description": "any value is invalid",
"data": "foo",
"valid": false
}
]
},
{
"description": "allOf with one empty schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{}
]
},
"tests": [
{
"description": "any data is valid",
"data": 1,
"valid": true
}
]
},
{
"description": "allOf with two empty schemas",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{},
{}
]
},
"tests": [
{
"description": "any data is valid",
"data": 1,
"valid": true
}
]
},
{
"description": "allOf with the first empty schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{},
{ "type": "number" }
]
},
"tests": [
{
"description": "number is valid",
"data": 1,
"valid": true
},
{
"description": "string is invalid",
"data": "foo",
"valid": false
}
]
},
{
"description": "allOf with the last empty schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{ "type": "number" },
{}
]
},
"tests": [
{
"description": "number is valid",
"data": 1,
"valid": true
},
{
"description": "string is invalid",
"data": "foo",
"valid": false
}
]
},
{
"description": "nested allOf, to check validation semantics",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{
"allOf": [
{
"type": "null"
}
]
}
]
},
"tests": [
{
"description": "null is valid",
"data": null,
"valid": true
},
{
"description": "anything non-null is invalid",
"data": 123,
"valid": false
}
]
},
{
"description": "allOf combined with anyOf, oneOf",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [ { "multipleOf": 2 } ],
"anyOf": [ { "multipleOf": 3 } ],
"oneOf": [ { "multipleOf": 5 } ]
},
"tests": [
{
"description": "allOf: false, anyOf: false, oneOf: false",
"data": 1,
"valid": false
},
{
"description": "allOf: false, anyOf: false, oneOf: true",
"data": 5,
"valid": false
},
{
"description": "allOf: false, anyOf: true, oneOf: false",
"data": 3,
"valid": false
},
{
"description": "allOf: false, anyOf: true, oneOf: true",
"data": 15,
"valid": false
},
{
"description": "allOf: true, anyOf: false, oneOf: false",
"data": 2,
"valid": false
},
{
"description": "allOf: true, anyOf: false, oneOf: true",
"data": 10,
"valid": false
},
{
"description": "allOf: true, anyOf: true, oneOf: false",
"data": 6,
"valid": false
},
{
"description": "allOf: true, anyOf: true, oneOf: true",
"data": 30,
"valid": true
}
]
}
]
@@ -0,0 +1,120 @@
[
{
"description": "Location-independent identifier",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "#foo",
"$defs": {
"A": {
"$anchor": "foo",
"type": "integer"
}
}
},
"tests": [
{
"data": 1,
"description": "match",
"valid": true
},
{
"data": "a",
"description": "mismatch",
"valid": false
}
]
},
{
"description": "Location-independent identifier with absolute URI",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "http://localhost:1234/draft2020-12/bar#foo",
"$defs": {
"A": {
"$id": "http://localhost:1234/draft2020-12/bar",
"$anchor": "foo",
"type": "integer"
}
}
},
"tests": [
{
"data": 1,
"description": "match",
"valid": true
},
{
"data": "a",
"description": "mismatch",
"valid": false
}
]
},
{
"description": "Location-independent identifier with base URI change in subschema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://localhost:1234/draft2020-12/root",
"$ref": "http://localhost:1234/draft2020-12/nested.json#foo",
"$defs": {
"A": {
"$id": "nested.json",
"$defs": {
"B": {
"$anchor": "foo",
"type": "integer"
}
}
}
}
},
"tests": [
{
"data": 1,
"description": "match",
"valid": true
},
{
"data": "a",
"description": "mismatch",
"valid": false
}
]
},
{
"description": "same $anchor with different base uri",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://localhost:1234/draft2020-12/foobar",
"$defs": {
"A": {
"$id": "child1",
"allOf": [
{
"$id": "child2",
"$anchor": "my_anchor",
"type": "number"
},
{
"$anchor": "my_anchor",
"type": "string"
}
]
}
},
"$ref": "child1#my_anchor"
},
"tests": [
{
"description": "$ref resolves to /$defs/A/allOf/1",
"data": "a",
"valid": true
},
{
"description": "$ref does not resolve to /$defs/A/allOf/0",
"data": 1,
"valid": false
}
]
}
]
@@ -0,0 +1,203 @@
[
{
"description": "anyOf",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"anyOf": [
{
"type": "integer"
},
{
"minimum": 2
}
]
},
"tests": [
{
"description": "first anyOf valid",
"data": 1,
"valid": true
},
{
"description": "second anyOf valid",
"data": 2.5,
"valid": true
},
{
"description": "both anyOf valid",
"data": 3,
"valid": true
},
{
"description": "neither anyOf valid",
"data": 1.5,
"valid": false
}
]
},
{
"description": "anyOf with base schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"anyOf" : [
{
"maxLength": 2
},
{
"minLength": 4
}
]
},
"tests": [
{
"description": "mismatch base schema",
"data": 3,
"valid": false
},
{
"description": "one anyOf valid",
"data": "foobar",
"valid": true
},
{
"description": "both anyOf invalid",
"data": "foo",
"valid": false
}
]
},
{
"description": "anyOf with boolean schemas, all true",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"anyOf": [true, true]
},
"tests": [
{
"description": "any value is valid",
"data": "foo",
"valid": true
}
]
},
{
"description": "anyOf with boolean schemas, some true",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"anyOf": [true, false]
},
"tests": [
{
"description": "any value is valid",
"data": "foo",
"valid": true
}
]
},
{
"description": "anyOf with boolean schemas, all false",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"anyOf": [false, false]
},
"tests": [
{
"description": "any value is invalid",
"data": "foo",
"valid": false
}
]
},
{
"description": "anyOf complex types",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"anyOf": [
{
"properties": {
"bar": {"type": "integer"}
},
"required": ["bar"]
},
{
"properties": {
"foo": {"type": "string"}
},
"required": ["foo"]
}
]
},
"tests": [
{
"description": "first anyOf valid (complex)",
"data": {"bar": 2},
"valid": true
},
{
"description": "second anyOf valid (complex)",
"data": {"foo": "baz"},
"valid": true
},
{
"description": "both anyOf valid (complex)",
"data": {"foo": "baz", "bar": 2},
"valid": true
},
{
"description": "neither anyOf valid (complex)",
"data": {"foo": 2, "bar": "quux"},
"valid": false
}
]
},
{
"description": "anyOf with one empty schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"anyOf": [
{ "type": "number" },
{}
]
},
"tests": [
{
"description": "string is valid",
"data": "foo",
"valid": true
},
{
"description": "number is valid",
"data": 123,
"valid": true
}
]
},
{
"description": "nested anyOf, to check validation semantics",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"anyOf": [
{
"anyOf": [
{
"type": "null"
}
]
}
]
},
"tests": [
{
"description": "null is valid",
"data": null,
"valid": true
},
{
"description": "anything non-null is invalid",
"data": 123,
"valid": false
}
]
}
]
@@ -0,0 +1,104 @@
[
{
"description": "boolean schema 'true'",
"schema": true,
"tests": [
{
"description": "number is valid",
"data": 1,
"valid": true
},
{
"description": "string is valid",
"data": "foo",
"valid": true
},
{
"description": "boolean true is valid",
"data": true,
"valid": true
},
{
"description": "boolean false is valid",
"data": false,
"valid": true
},
{
"description": "null is valid",
"data": null,
"valid": true
},
{
"description": "object is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "empty object is valid",
"data": {},
"valid": true
},
{
"description": "array is valid",
"data": ["foo"],
"valid": true
},
{
"description": "empty array is valid",
"data": [],
"valid": true
}
]
},
{
"description": "boolean schema 'false'",
"schema": false,
"tests": [
{
"description": "number is invalid",
"data": 1,
"valid": false
},
{
"description": "string is invalid",
"data": "foo",
"valid": false
},
{
"description": "boolean true is invalid",
"data": true,
"valid": false
},
{
"description": "boolean false is invalid",
"data": false,
"valid": false
},
{
"description": "null is invalid",
"data": null,
"valid": false
},
{
"description": "object is invalid",
"data": {"foo": "bar"},
"valid": false
},
{
"description": "empty object is invalid",
"data": {},
"valid": false
},
{
"description": "array is invalid",
"data": ["foo"],
"valid": false
},
{
"description": "empty array is invalid",
"data": [],
"valid": false
}
]
}
]
@@ -0,0 +1,431 @@
[
{
"description": "const validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": 2
},
"tests": [
{
"description": "same value is valid",
"data": 2,
"valid": true
},
{
"description": "another value is invalid",
"data": 5,
"valid": false
},
{
"description": "another type is invalid",
"data": "a",
"valid": false
}
]
},
{
"description": "const with object",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": {"foo": "bar", "baz": "bax"}
},
"tests": [
{
"description": "same object is valid",
"data": {"foo": "bar", "baz": "bax"},
"valid": true
},
{
"description": "same object with different property order is valid",
"data": {"baz": "bax", "foo": "bar"},
"valid": true
},
{
"description": "another object is invalid",
"data": {"foo": "bar"},
"valid": false
},
{
"description": "another type is invalid",
"data": [1, 2],
"valid": false
}
]
},
{
"description": "const with array",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": [{ "foo": "bar" }]
},
"tests": [
{
"description": "same array is valid",
"data": [{"foo": "bar"}],
"valid": true
},
{
"description": "another array item is invalid",
"data": [2],
"valid": false
},
{
"description": "array with additional items is invalid",
"data": [1, 2, 3],
"valid": false
}
]
},
{
"description": "const with null",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": null
},
"tests": [
{
"description": "null is valid",
"data": null,
"valid": true
},
{
"description": "not null is invalid",
"data": 0,
"valid": false
}
]
},
{
"description": "const with false does not match 0",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": false
},
"tests": [
{
"description": "false is valid",
"data": false,
"valid": true
},
{
"description": "integer zero is invalid",
"data": 0,
"valid": false
},
{
"description": "float zero is invalid",
"data": 0.0,
"valid": false
}
]
},
{
"description": "const with true does not match 1",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": true
},
"tests": [
{
"description": "true is valid",
"data": true,
"valid": true
},
{
"description": "integer one is invalid",
"data": 1,
"valid": false
},
{
"description": "float one is invalid",
"data": 1.0,
"valid": false
}
]
},
{
"description": "const with [false] does not match [0]",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": [false]
},
"tests": [
{
"description": "[false] is valid",
"data": [false],
"valid": true
},
{
"description": "[0] is invalid",
"data": [0],
"valid": false
},
{
"description": "[0.0] is invalid",
"data": [0.0],
"valid": false
}
]
},
{
"description": "const with [true] does not match [1]",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": [true]
},
"tests": [
{
"description": "[true] is valid",
"data": [true],
"valid": true
},
{
"description": "[1] is invalid",
"data": [1],
"valid": false
},
{
"description": "[1.0] is invalid",
"data": [1.0],
"valid": false
}
]
},
{
"description": "const with {\"a\": false} does not match {\"a\": 0}",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": {"a": false}
},
"tests": [
{
"description": "{\"a\": false} is valid",
"data": {"a": false},
"valid": true
},
{
"description": "{\"a\": 0} is invalid",
"data": {"a": 0},
"valid": false
},
{
"description": "{\"a\": 0.0} is invalid",
"data": {"a": 0.0},
"valid": false
}
]
},
{
"description": "const with {\"a\": true} does not match {\"a\": 1}",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": {"a": true}
},
"tests": [
{
"description": "{\"a\": true} is valid",
"data": {"a": true},
"valid": true
},
{
"description": "{\"a\": 1} is invalid",
"data": {"a": 1},
"valid": false
},
{
"description": "{\"a\": 1.0} is invalid",
"data": {"a": 1.0},
"valid": false
}
]
},
{
"description": "const with 0 does not match other zero-like types",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": 0
},
"tests": [
{
"description": "false is invalid",
"data": false,
"valid": false
},
{
"description": "integer zero is valid",
"data": 0,
"valid": true
},
{
"description": "float zero is valid",
"data": 0.0,
"valid": true
},
{
"description": "empty object is invalid",
"data": {},
"valid": false
},
{
"description": "empty array is invalid",
"data": [],
"valid": false
},
{
"description": "empty string is invalid",
"data": "",
"valid": false
}
]
},
{
"description": "const with 1 does not match true",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": 1
},
"tests": [
{
"description": "true is invalid",
"data": true,
"valid": false
},
{
"description": "integer one is valid",
"data": 1,
"valid": true
},
{
"description": "float one is valid",
"data": 1.0,
"valid": true
}
]
},
{
"description": "const with -2.0 matches integer and float types",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": -2.0
},
"tests": [
{
"description": "integer -2 is valid",
"data": -2,
"valid": true
},
{
"description": "integer 2 is invalid",
"data": 2,
"valid": false
},
{
"description": "float -2.0 is valid",
"data": -2.0,
"valid": true
},
{
"description": "float 2.0 is invalid",
"data": 2.0,
"valid": false
},
{
"description": "float -2.00001 is invalid",
"data": -2.00001,
"valid": false
}
]
},
{
"description": "float and integers are equal up to 64-bit representation limits",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": 9007199254740992
},
"tests": [
{
"description": "integer is valid",
"data": 9007199254740992,
"valid": true
},
{
"description": "integer minus one is invalid",
"data": 9007199254740991,
"valid": false
},
{
"description": "float is valid",
"data": 9007199254740992.0,
"valid": true
},
{
"description": "float minus one is invalid",
"data": 9007199254740991.0,
"valid": false
}
]
},
{
"description": "nul characters in strings",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": "hello\u0000there"
},
"tests": [
{
"description": "match string with nul",
"data": "hello\u0000there",
"valid": true
},
{
"description": "do not match string lacking nul",
"data": "hellothere",
"valid": false
}
]
},
{
"description": "characters with the same visual representation but different codepoint",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": "μ",
"$comment": "U+03BC"
},
"tests": [
{
"description": "character uses the same codepoint",
"data": "μ",
"comment": "U+03BC",
"valid": true
},
{
"description": "character looks the same but uses a different codepoint",
"data": "µ",
"comment": "U+00B5",
"valid": false
}
]
},
{
"description": "characters with the same visual representation, but different number of codepoints",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"const": "ä",
"$comment": "U+00E4"
},
"tests": [
{
"description": "character uses the same codepoint",
"data": "ä",
"comment": "U+00E4",
"valid": true
},
{
"description": "character looks the same but uses combining marks",
"data": "ä",
"comment": "a, U+0308",
"valid": false
}
]
}
]
@@ -0,0 +1,176 @@
[
{
"description": "contains keyword validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {"minimum": 5}
},
"tests": [
{
"description": "array with item matching schema (5) is valid",
"data": [3, 4, 5],
"valid": true
},
{
"description": "array with item matching schema (6) is valid",
"data": [3, 4, 6],
"valid": true
},
{
"description": "array with two items matching schema (5, 6) is valid",
"data": [3, 4, 5, 6],
"valid": true
},
{
"description": "array without items matching schema is invalid",
"data": [2, 3, 4],
"valid": false
},
{
"description": "empty array is invalid",
"data": [],
"valid": false
},
{
"description": "not array is valid",
"data": {},
"valid": true
}
]
},
{
"description": "contains keyword with const keyword",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": { "const": 5 }
},
"tests": [
{
"description": "array with item 5 is valid",
"data": [3, 4, 5],
"valid": true
},
{
"description": "array with two items 5 is valid",
"data": [3, 4, 5, 5],
"valid": true
},
{
"description": "array without item 5 is invalid",
"data": [1, 2, 3, 4],
"valid": false
}
]
},
{
"description": "contains keyword with boolean schema true",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": true
},
"tests": [
{
"description": "any non-empty array is valid",
"data": ["foo"],
"valid": true
},
{
"description": "empty array is invalid",
"data": [],
"valid": false
}
]
},
{
"description": "contains keyword with boolean schema false",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": false
},
"tests": [
{
"description": "any non-empty array is invalid",
"data": ["foo"],
"valid": false
},
{
"description": "empty array is invalid",
"data": [],
"valid": false
},
{
"description": "non-arrays are valid",
"data": "contains does not apply to strings",
"valid": true
}
]
},
{
"description": "items + contains",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"items": { "multipleOf": 2 },
"contains": { "multipleOf": 3 }
},
"tests": [
{
"description": "matches items, does not match contains",
"data": [ 2, 4, 8 ],
"valid": false
},
{
"description": "does not match items, matches contains",
"data": [ 3, 6, 9 ],
"valid": false
},
{
"description": "matches both items and contains",
"data": [ 6, 12 ],
"valid": true
},
{
"description": "matches neither items nor contains",
"data": [ 1, 5 ],
"valid": false
}
]
},
{
"description": "contains with false if subschema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {
"if": false,
"else": true
}
},
"tests": [
{
"description": "any non-empty array is valid",
"data": ["foo"],
"valid": true
},
{
"description": "empty array is invalid",
"data": [],
"valid": false
}
]
},
{
"description": "contains with null instance elements",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {
"type": "null"
}
},
"tests": [
{
"description": "allows null items",
"data": [ null ],
"valid": true
}
]
}
]
@@ -0,0 +1,131 @@
[
{
"description": "validation of string-encoded content based on media type",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contentMediaType": "application/json"
},
"tests": [
{
"description": "a valid JSON document",
"data": "{\"foo\": \"bar\"}",
"valid": true
},
{
"description": "an invalid JSON document; validates true",
"data": "{:}",
"valid": true
},
{
"description": "ignores non-strings",
"data": 100,
"valid": true
}
]
},
{
"description": "validation of binary string-encoding",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contentEncoding": "base64"
},
"tests": [
{
"description": "a valid base64 string",
"data": "eyJmb28iOiAiYmFyIn0K",
"valid": true
},
{
"description": "an invalid base64 string (% is not a valid character); validates true",
"data": "eyJmb28iOi%iYmFyIn0K",
"valid": true
},
{
"description": "ignores non-strings",
"data": 100,
"valid": true
}
]
},
{
"description": "validation of binary-encoded media type documents",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contentMediaType": "application/json",
"contentEncoding": "base64"
},
"tests": [
{
"description": "a valid base64-encoded JSON document",
"data": "eyJmb28iOiAiYmFyIn0K",
"valid": true
},
{
"description": "a validly-encoded invalid JSON document; validates true",
"data": "ezp9Cg==",
"valid": true
},
{
"description": "an invalid base64 string that is valid JSON; validates true",
"data": "{}",
"valid": true
},
{
"description": "ignores non-strings",
"data": 100,
"valid": true
}
]
},
{
"description": "validation of binary-encoded media type documents with schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contentMediaType": "application/json",
"contentEncoding": "base64",
"contentSchema": { "type": "object", "required": ["foo"], "properties": { "foo": { "type": "string" } } }
},
"tests": [
{
"description": "a valid base64-encoded JSON document",
"data": "eyJmb28iOiAiYmFyIn0K",
"valid": true
},
{
"description": "another valid base64-encoded JSON document",
"data": "eyJib28iOiAyMCwgImZvbyI6ICJiYXoifQ==",
"valid": true
},
{
"description": "an invalid base64-encoded JSON document; validates true",
"data": "eyJib28iOiAyMH0=",
"valid": true
},
{
"description": "an empty object as a base64-encoded JSON document; validates true",
"data": "e30=",
"valid": true
},
{
"description": "an empty array as a base64-encoded JSON document",
"data": "W10=",
"valid": true
},
{
"description": "a validly-encoded invalid JSON document; validates true",
"data": "ezp9Cg==",
"valid": true
},
{
"description": "an invalid base64 string that is valid JSON; validates true",
"data": "{}",
"valid": true
},
{
"description": "ignores non-strings",
"data": 100,
"valid": true
}
]
}
]
@@ -0,0 +1,82 @@
[
{
"description": "invalid type for default",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": {
"type": "integer",
"default": []
}
}
},
"tests": [
{
"description": "valid when property is specified",
"data": {"foo": 13},
"valid": true
},
{
"description": "still valid when the invalid default is used",
"data": {},
"valid": true
}
]
},
{
"description": "invalid string value for default",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"bar": {
"type": "string",
"minLength": 4,
"default": "bad"
}
}
},
"tests": [
{
"description": "valid when property is specified",
"data": {"bar": "good"},
"valid": true
},
{
"description": "still valid when the invalid default is used",
"data": {},
"valid": true
}
]
},
{
"description": "the default keyword does not do anything if the property is missing",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"alpha": {
"type": "number",
"maximum": 3,
"default": 5
}
}
},
"tests": [
{
"description": "an explicit property value is checked against maximum (passing)",
"data": { "alpha": 1 },
"valid": true
},
{
"description": "an explicit property value is checked against maximum (failing)",
"data": { "alpha": 5 },
"valid": false
},
{
"description": "missing properties are not filled in with the default",
"data": {},
"valid": true
}
]
}
]
@@ -0,0 +1,21 @@
[
{
"description": "validate definition against metaschema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "https://json-schema.org/draft/2020-12/schema"
},
"tests": [
{
"description": "valid definition schema",
"data": {"$defs": {"foo": {"type": "integer"}}},
"valid": true
},
{
"description": "invalid definition schema",
"data": {"$defs": {"foo": {"type": 1}}},
"valid": false
}
]
}
]
@@ -0,0 +1,152 @@
[
{
"description": "single dependency",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependentRequired": {"bar": ["foo"]}
},
"tests": [
{
"description": "neither",
"data": {},
"valid": true
},
{
"description": "nondependant",
"data": {"foo": 1},
"valid": true
},
{
"description": "with dependency",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "missing dependency",
"data": {"bar": 2},
"valid": false
},
{
"description": "ignores arrays",
"data": ["bar"],
"valid": true
},
{
"description": "ignores strings",
"data": "foobar",
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
}
]
},
{
"description": "empty dependents",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependentRequired": {"bar": []}
},
"tests": [
{
"description": "empty object",
"data": {},
"valid": true
},
{
"description": "object with one property",
"data": {"bar": 2},
"valid": true
},
{
"description": "non-object is valid",
"data": 1,
"valid": true
}
]
},
{
"description": "multiple dependents required",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependentRequired": {"quux": ["foo", "bar"]}
},
"tests": [
{
"description": "neither",
"data": {},
"valid": true
},
{
"description": "nondependants",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "with dependencies",
"data": {"foo": 1, "bar": 2, "quux": 3},
"valid": true
},
{
"description": "missing dependency",
"data": {"foo": 1, "quux": 2},
"valid": false
},
{
"description": "missing other dependency",
"data": {"bar": 1, "quux": 2},
"valid": false
},
{
"description": "missing both dependencies",
"data": {"quux": 1},
"valid": false
}
]
},
{
"description": "dependencies with escaped characters",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependentRequired": {
"foo\nbar": ["foo\rbar"],
"foo\"bar": ["foo'bar"]
}
},
"tests": [
{
"description": "CRLF",
"data": {
"foo\nbar": 1,
"foo\rbar": 2
},
"valid": true
},
{
"description": "quoted quotes",
"data": {
"foo'bar": 1,
"foo\"bar": 2
},
"valid": true
},
{
"description": "CRLF missing dependent",
"data": {
"foo\nbar": 1,
"foo": 2
},
"valid": false
},
{
"description": "quoted quotes missing dependent",
"data": {
"foo\"bar": 2
},
"valid": false
}
]
}
]
@@ -0,0 +1,171 @@
[
{
"description": "single dependency",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependentSchemas": {
"bar": {
"properties": {
"foo": {"type": "integer"},
"bar": {"type": "integer"}
}
}
}
},
"tests": [
{
"description": "valid",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "no dependency",
"data": {"foo": "quux"},
"valid": true
},
{
"description": "wrong type",
"data": {"foo": "quux", "bar": 2},
"valid": false
},
{
"description": "wrong type other",
"data": {"foo": 2, "bar": "quux"},
"valid": false
},
{
"description": "wrong type both",
"data": {"foo": "quux", "bar": "quux"},
"valid": false
},
{
"description": "ignores arrays",
"data": ["bar"],
"valid": true
},
{
"description": "ignores strings",
"data": "foobar",
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
}
]
},
{
"description": "boolean subschemas",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependentSchemas": {
"foo": true,
"bar": false
}
},
"tests": [
{
"description": "object with property having schema true is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "object with property having schema false is invalid",
"data": {"bar": 2},
"valid": false
},
{
"description": "object with both properties is invalid",
"data": {"foo": 1, "bar": 2},
"valid": false
},
{
"description": "empty object is valid",
"data": {},
"valid": true
}
]
},
{
"description": "dependencies with escaped characters",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependentSchemas": {
"foo\tbar": {"minProperties": 4},
"foo'bar": {"required": ["foo\"bar"]}
}
},
"tests": [
{
"description": "quoted tab",
"data": {
"foo\tbar": 1,
"a": 2,
"b": 3,
"c": 4
},
"valid": true
},
{
"description": "quoted quote",
"data": {
"foo'bar": {"foo\"bar": 1}
},
"valid": false
},
{
"description": "quoted tab invalid under dependent schema",
"data": {
"foo\tbar": 1,
"a": 2
},
"valid": false
},
{
"description": "quoted quote invalid under dependent schema",
"data": {"foo'bar": 1},
"valid": false
}
]
},
{
"description": "dependent subschema incompatible with root",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": {}
},
"dependentSchemas": {
"foo": {
"properties": {
"bar": {}
},
"additionalProperties": false
}
}
},
"tests": [
{
"description": "matches root",
"data": {"foo": 1},
"valid": false
},
{
"description": "matches dependency",
"data": {"bar": 1},
"valid": true
},
{
"description": "matches both",
"data": {"foo": 1, "bar": 2},
"valid": false
},
{
"description": "no dependency",
"data": {"baz": 1},
"valid": true
}
]
}
]
@@ -0,0 +1,873 @@
[
{
"description": "A $dynamicRef to a $dynamicAnchor in the same schema resource behaves like a normal $ref to an $anchor",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/dynamicRef-dynamicAnchor-same-schema/root",
"type": "array",
"items": { "$dynamicRef": "#items" },
"$defs": {
"foo": {
"$dynamicAnchor": "items",
"type": "string"
}
}
},
"tests": [
{
"description": "An array of strings is valid",
"data": ["foo", "bar"],
"valid": true
},
{
"description": "An array containing non-strings is invalid",
"data": ["foo", 42],
"valid": false
}
]
},
{
"description": "A $dynamicRef to an $anchor in the same schema resource behaves like a normal $ref to an $anchor",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/dynamicRef-anchor-same-schema/root",
"type": "array",
"items": { "$dynamicRef": "#items" },
"$defs": {
"foo": {
"$anchor": "items",
"type": "string"
}
}
},
"tests": [
{
"description": "An array of strings is valid",
"data": ["foo", "bar"],
"valid": true
},
{
"description": "An array containing non-strings is invalid",
"data": ["foo", 42],
"valid": false
}
]
},
{
"description": "A $ref to a $dynamicAnchor in the same schema resource behaves like a normal $ref to an $anchor",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/ref-dynamicAnchor-same-schema/root",
"type": "array",
"items": { "$ref": "#items" },
"$defs": {
"foo": {
"$dynamicAnchor": "items",
"type": "string"
}
}
},
"tests": [
{
"description": "An array of strings is valid",
"data": ["foo", "bar"],
"valid": true
},
{
"description": "An array containing non-strings is invalid",
"data": ["foo", 42],
"valid": false
}
]
},
{
"description": "A $dynamicRef resolves to the first $dynamicAnchor still in scope that is encountered when the schema is evaluated",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/typical-dynamic-resolution/root",
"$ref": "list",
"$defs": {
"foo": {
"$dynamicAnchor": "items",
"type": "string"
},
"list": {
"$id": "list",
"type": "array",
"items": { "$dynamicRef": "#items" },
"$defs": {
"items": {
"$comment": "This is only needed to satisfy the bookending requirement",
"$dynamicAnchor": "items"
}
}
}
}
},
"tests": [
{
"description": "An array of strings is valid",
"data": ["foo", "bar"],
"valid": true
},
{
"description": "An array containing non-strings is invalid",
"data": ["foo", 42],
"valid": false
}
]
},
{
"description": "A $dynamicRef without anchor in fragment behaves identical to $ref",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/dynamicRef-without-anchor/root",
"$ref": "list",
"$defs": {
"foo": {
"$dynamicAnchor": "items",
"type": "string"
},
"list": {
"$id": "list",
"type": "array",
"items": { "$dynamicRef": "#/$defs/items" },
"$defs": {
"items": {
"$comment": "This is only needed to satisfy the bookending requirement",
"$dynamicAnchor": "items",
"type": "number"
}
}
}
}
},
"tests": [
{
"description": "An array of strings is invalid",
"data": ["foo", "bar"],
"valid": false
},
{
"description": "An array of numbers is valid",
"data": [24, 42],
"valid": true
}
]
},
{
"description": "A $dynamicRef with intermediate scopes that don't include a matching $dynamicAnchor does not affect dynamic scope resolution",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/dynamic-resolution-with-intermediate-scopes/root",
"$ref": "intermediate-scope",
"$defs": {
"foo": {
"$dynamicAnchor": "items",
"type": "string"
},
"intermediate-scope": {
"$id": "intermediate-scope",
"$ref": "list"
},
"list": {
"$id": "list",
"type": "array",
"items": { "$dynamicRef": "#items" },
"$defs": {
"items": {
"$comment": "This is only needed to satisfy the bookending requirement",
"$dynamicAnchor": "items"
}
}
}
}
},
"tests": [
{
"description": "An array of strings is valid",
"data": ["foo", "bar"],
"valid": true
},
{
"description": "An array containing non-strings is invalid",
"data": ["foo", 42],
"valid": false
}
]
},
{
"description": "An $anchor with the same name as a $dynamicAnchor is not used for dynamic scope resolution",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/dynamic-resolution-ignores-anchors/root",
"$ref": "list",
"$defs": {
"foo": {
"$anchor": "items",
"type": "string"
},
"list": {
"$id": "list",
"type": "array",
"items": { "$dynamicRef": "#items" },
"$defs": {
"items": {
"$comment": "This is only needed to satisfy the bookending requirement",
"$dynamicAnchor": "items"
}
}
}
}
},
"tests": [
{
"description": "Any array is valid",
"data": ["foo", 42],
"valid": true
}
]
},
{
"description": "A $dynamicRef without a matching $dynamicAnchor in the same schema resource behaves like a normal $ref to $anchor",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/dynamic-resolution-without-bookend/root",
"$ref": "list",
"$defs": {
"foo": {
"$dynamicAnchor": "items",
"type": "string"
},
"list": {
"$id": "list",
"type": "array",
"items": { "$dynamicRef": "#items" },
"$defs": {
"items": {
"$comment": "This is only needed to give the reference somewhere to resolve to when it behaves like $ref",
"$anchor": "items"
}
}
}
}
},
"tests": [
{
"description": "Any array is valid",
"data": ["foo", 42],
"valid": true
}
]
},
{
"description": "A $dynamicRef with a non-matching $dynamicAnchor in the same schema resource behaves like a normal $ref to $anchor",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/unmatched-dynamic-anchor/root",
"$ref": "list",
"$defs": {
"foo": {
"$dynamicAnchor": "items",
"type": "string"
},
"list": {
"$id": "list",
"type": "array",
"items": { "$dynamicRef": "#items" },
"$defs": {
"items": {
"$comment": "This is only needed to give the reference somewhere to resolve to when it behaves like $ref",
"$anchor": "items",
"$dynamicAnchor": "foo"
}
}
}
}
},
"tests": [
{
"description": "Any array is valid",
"data": ["foo", 42],
"valid": true
}
]
},
{
"description": "A $dynamicRef that initially resolves to a schema with a matching $dynamicAnchor resolves to the first $dynamicAnchor in the dynamic scope",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/relative-dynamic-reference/root",
"$dynamicAnchor": "meta",
"type": "object",
"properties": {
"foo": { "const": "pass" }
},
"$ref": "extended",
"$defs": {
"extended": {
"$id": "extended",
"$dynamicAnchor": "meta",
"type": "object",
"properties": {
"bar": { "$ref": "bar" }
}
},
"bar": {
"$id": "bar",
"type": "object",
"properties": {
"baz": { "$dynamicRef": "extended#meta" }
}
}
}
},
"tests": [
{
"description": "The recursive part is valid against the root",
"data": {
"foo": "pass",
"bar": {
"baz": { "foo": "pass" }
}
},
"valid": true
},
{
"description": "The recursive part is not valid against the root",
"data": {
"foo": "pass",
"bar": {
"baz": { "foo": "fail" }
}
},
"valid": false
}
]
},
{
"description": "A $dynamicRef that initially resolves to a schema without a matching $dynamicAnchor behaves like a normal $ref to $anchor",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/relative-dynamic-reference-without-bookend/root",
"$dynamicAnchor": "meta",
"type": "object",
"properties": {
"foo": { "const": "pass" }
},
"$ref": "extended",
"$defs": {
"extended": {
"$id": "extended",
"$anchor": "meta",
"type": "object",
"properties": {
"bar": { "$ref": "bar" }
}
},
"bar": {
"$id": "bar",
"type": "object",
"properties": {
"baz": { "$dynamicRef": "extended#meta" }
}
}
}
},
"tests": [
{
"description": "The recursive part doesn't need to validate against the root",
"data": {
"foo": "pass",
"bar": {
"baz": { "foo": "fail" }
}
},
"valid": true
}
]
},
{
"description": "multiple dynamic paths to the $dynamicRef keyword",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/dynamic-ref-with-multiple-paths/main",
"if": {
"properties": {
"kindOfList": { "const": "numbers" }
},
"required": ["kindOfList"]
},
"then": { "$ref": "numberList" },
"else": { "$ref": "stringList" },
"$defs": {
"genericList": {
"$id": "genericList",
"properties": {
"list": {
"items": { "$dynamicRef": "#itemType" }
}
},
"$defs": {
"defaultItemType": {
"$comment": "Only needed to satisfy bookending requirement",
"$dynamicAnchor": "itemType"
}
}
},
"numberList": {
"$id": "numberList",
"$defs": {
"itemType": {
"$dynamicAnchor": "itemType",
"type": "number"
}
},
"$ref": "genericList"
},
"stringList": {
"$id": "stringList",
"$defs": {
"itemType": {
"$dynamicAnchor": "itemType",
"type": "string"
}
},
"$ref": "genericList"
}
}
},
"tests": [
{
"description": "number list with number values",
"data": {
"kindOfList": "numbers",
"list": [1.1]
},
"valid": true
},
{
"description": "number list with string values",
"data": {
"kindOfList": "numbers",
"list": ["foo"]
},
"valid": false
},
{
"description": "string list with number values",
"data": {
"kindOfList": "strings",
"list": [1.1]
},
"valid": false
},
{
"description": "string list with string values",
"data": {
"kindOfList": "strings",
"list": ["foo"]
},
"valid": true
}
]
},
{
"description": "after leaving a dynamic scope, it is not used by a $dynamicRef",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/dynamic-ref-leaving-dynamic-scope/main",
"if": {
"$id": "first_scope",
"$defs": {
"thingy": {
"$comment": "this is first_scope#thingy",
"$dynamicAnchor": "thingy",
"type": "number"
}
}
},
"then": {
"$id": "second_scope",
"$ref": "start",
"$defs": {
"thingy": {
"$comment": "this is second_scope#thingy, the final destination of the $dynamicRef",
"$dynamicAnchor": "thingy",
"type": "null"
}
}
},
"$defs": {
"start": {
"$comment": "this is the landing spot from $ref",
"$id": "start",
"$dynamicRef": "inner_scope#thingy"
},
"thingy": {
"$comment": "this is the first stop for the $dynamicRef",
"$id": "inner_scope",
"$dynamicAnchor": "thingy",
"type": "string"
}
}
},
"tests": [
{
"description": "string matches /$defs/thingy, but the $dynamicRef does not stop here",
"data": "a string",
"valid": false
},
{
"description": "first_scope is not in dynamic scope for the $dynamicRef",
"data": 42,
"valid": false
},
{
"description": "/then/$defs/thingy is the final stop for the $dynamicRef",
"data": null,
"valid": true
}
]
},
{
"description": "strict-tree schema, guards against misspelled properties",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://localhost:1234/draft2020-12/strict-tree.json",
"$dynamicAnchor": "node",
"$ref": "tree.json",
"unevaluatedProperties": false
},
"tests": [
{
"description": "instance with misspelled field",
"data": {
"children": [{
"daat": 1
}]
},
"valid": false
},
{
"description": "instance with correct field",
"data": {
"children": [{
"data": 1
}]
},
"valid": true
}
]
},
{
"description": "tests for implementation dynamic anchor and reference link",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://localhost:1234/draft2020-12/strict-extendible.json",
"$ref": "extendible-dynamic-ref.json",
"$defs": {
"elements": {
"$dynamicAnchor": "elements",
"properties": {
"a": true
},
"required": ["a"],
"additionalProperties": false
}
}
},
"tests": [
{
"description": "incorrect parent schema",
"data": {
"a": true
},
"valid": false
},
{
"description": "incorrect extended schema",
"data": {
"elements": [
{ "b": 1 }
]
},
"valid": false
},
{
"description": "correct extended schema",
"data": {
"elements": [
{ "a": 1 }
]
},
"valid": true
}
]
},
{
"description": "$ref and $dynamicAnchor are independent of order - $defs first",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://localhost:1234/draft2020-12/strict-extendible-allof-defs-first.json",
"allOf": [
{
"$ref": "extendible-dynamic-ref.json"
},
{
"$defs": {
"elements": {
"$dynamicAnchor": "elements",
"properties": {
"a": true
},
"required": ["a"],
"additionalProperties": false
}
}
}
]
},
"tests": [
{
"description": "incorrect parent schema",
"data": {
"a": true
},
"valid": false
},
{
"description": "incorrect extended schema",
"data": {
"elements": [
{ "b": 1 }
]
},
"valid": false
},
{
"description": "correct extended schema",
"data": {
"elements": [
{ "a": 1 }
]
},
"valid": true
}
]
},
{
"description": "$ref and $dynamicAnchor are independent of order - $ref first",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://localhost:1234/draft2020-12/strict-extendible-allof-ref-first.json",
"allOf": [
{
"$defs": {
"elements": {
"$dynamicAnchor": "elements",
"properties": {
"a": true
},
"required": ["a"],
"additionalProperties": false
}
}
},
{
"$ref": "extendible-dynamic-ref.json"
}
]
},
"tests": [
{
"description": "incorrect parent schema",
"data": {
"a": true
},
"valid": false
},
{
"description": "incorrect extended schema",
"data": {
"elements": [
{ "b": 1 }
]
},
"valid": false
},
{
"description": "correct extended schema",
"data": {
"elements": [
{ "a": 1 }
]
},
"valid": true
}
]
},
{
"description": "$ref to $dynamicRef finds detached $dynamicAnchor",
"schema": {
"$ref": "http://localhost:1234/draft2020-12/detached-dynamicref.json#/$defs/foo"
},
"tests": [
{
"description": "number is valid",
"data": 1,
"valid": true
},
{
"description": "non-number is invalid",
"data": "a",
"valid": false
}
]
},
{
"description": "$dynamicRef points to a boolean schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$defs": {
"true": true,
"false": false
},
"properties": {
"true": {
"$dynamicRef": "#/$defs/true"
},
"false": {
"$dynamicRef": "#/$defs/false"
}
}
},
"tests": [
{
"description": "follow $dynamicRef to a true schema",
"data": { "true": 1 },
"valid": true
},
{
"description": "follow $dynamicRef to a false schema",
"data": { "false": 1 },
"valid": false
}
]
},
{
"description": "$dynamicRef skips over intermediate resources - direct reference",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/main",
"type": "object",
"properties": {
"bar-item": {
"$ref": "item"
}
},
"$defs": {
"bar": {
"$id": "bar",
"type": "array",
"items": {
"$ref": "item"
},
"$defs": {
"item": {
"$id": "item",
"type": "object",
"properties": {
"content": {
"$dynamicRef": "#content"
}
},
"$defs": {
"defaultContent": {
"$dynamicAnchor": "content",
"type": "integer"
}
}
},
"content": {
"$dynamicAnchor": "content",
"type": "string"
}
}
}
}
},
"tests": [
{
"description": "integer property passes",
"data": { "bar-item": { "content": 42 } },
"valid": true
},
{
"description": "string property fails",
"data": { "bar-item": { "content": "value" } },
"valid": false
}
]
},
{
"description": "$dynamicRef avoids the root of each schema, but scopes are still registered",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/dynamic-ref-avoids-root-of-each-schema/base",
"$ref": "first#/$defs/stuff",
"$defs": {
"first": {
"$id": "first",
"$defs": {
"stuff": {
"$ref": "second#/$defs/stuff"
},
"length": {
"$comment": "unused, because there is no $dynamicAnchor here",
"maxLength": 1
}
}
},
"second": {
"$id": "second",
"$defs": {
"stuff": {
"$ref": "third#/$defs/stuff"
},
"length": {
"$dynamicAnchor": "length",
"maxLength": 2
}
}
},
"third": {
"$id": "third",
"$defs": {
"stuff": {
"$dynamicRef": "#length"
},
"length": {
"$dynamicAnchor": "length",
"maxLength": 3
}
}
}
}
},
"tests": [
{
"description": "data is sufficient for schema at second#/$defs/length",
"data": "hi",
"valid": true
},
{
"description": "data is not sufficient for schema at second#/$defs/length",
"data": "hey",
"valid": false
}
]
}
]
@@ -0,0 +1,358 @@
[
{
"description": "simple enum validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": [1, 2, 3]
},
"tests": [
{
"description": "one of the enum is valid",
"data": 1,
"valid": true
},
{
"description": "something else is invalid",
"data": 4,
"valid": false
}
]
},
{
"description": "heterogeneous enum validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": [6, "foo", [], true, {"foo": 12}]
},
"tests": [
{
"description": "one of the enum is valid",
"data": [],
"valid": true
},
{
"description": "something else is invalid",
"data": null,
"valid": false
},
{
"description": "objects are deep compared",
"data": {"foo": false},
"valid": false
},
{
"description": "valid object matches",
"data": {"foo": 12},
"valid": true
},
{
"description": "extra properties in object is invalid",
"data": {"foo": 12, "boo": 42},
"valid": false
}
]
},
{
"description": "heterogeneous enum-with-null validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": [6, null]
},
"tests": [
{
"description": "null is valid",
"data": null,
"valid": true
},
{
"description": "number is valid",
"data": 6,
"valid": true
},
{
"description": "something else is invalid",
"data": "test",
"valid": false
}
]
},
{
"description": "enums in properties",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type":"object",
"properties": {
"foo": {"enum":["foo"]},
"bar": {"enum":["bar"]}
},
"required": ["bar"]
},
"tests": [
{
"description": "both properties are valid",
"data": {"foo":"foo", "bar":"bar"},
"valid": true
},
{
"description": "wrong foo value",
"data": {"foo":"foot", "bar":"bar"},
"valid": false
},
{
"description": "wrong bar value",
"data": {"foo":"foo", "bar":"bart"},
"valid": false
},
{
"description": "missing optional property is valid",
"data": {"bar":"bar"},
"valid": true
},
{
"description": "missing required property is invalid",
"data": {"foo":"foo"},
"valid": false
},
{
"description": "missing all properties is invalid",
"data": {},
"valid": false
}
]
},
{
"description": "enum with escaped characters",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": ["foo\nbar", "foo\rbar"]
},
"tests": [
{
"description": "member 1 is valid",
"data": "foo\nbar",
"valid": true
},
{
"description": "member 2 is valid",
"data": "foo\rbar",
"valid": true
},
{
"description": "another string is invalid",
"data": "abc",
"valid": false
}
]
},
{
"description": "enum with false does not match 0",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": [false]
},
"tests": [
{
"description": "false is valid",
"data": false,
"valid": true
},
{
"description": "integer zero is invalid",
"data": 0,
"valid": false
},
{
"description": "float zero is invalid",
"data": 0.0,
"valid": false
}
]
},
{
"description": "enum with [false] does not match [0]",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": [[false]]
},
"tests": [
{
"description": "[false] is valid",
"data": [false],
"valid": true
},
{
"description": "[0] is invalid",
"data": [0],
"valid": false
},
{
"description": "[0.0] is invalid",
"data": [0.0],
"valid": false
}
]
},
{
"description": "enum with true does not match 1",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": [true]
},
"tests": [
{
"description": "true is valid",
"data": true,
"valid": true
},
{
"description": "integer one is invalid",
"data": 1,
"valid": false
},
{
"description": "float one is invalid",
"data": 1.0,
"valid": false
}
]
},
{
"description": "enum with [true] does not match [1]",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": [[true]]
},
"tests": [
{
"description": "[true] is valid",
"data": [true],
"valid": true
},
{
"description": "[1] is invalid",
"data": [1],
"valid": false
},
{
"description": "[1.0] is invalid",
"data": [1.0],
"valid": false
}
]
},
{
"description": "enum with 0 does not match false",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": [0]
},
"tests": [
{
"description": "false is invalid",
"data": false,
"valid": false
},
{
"description": "integer zero is valid",
"data": 0,
"valid": true
},
{
"description": "float zero is valid",
"data": 0.0,
"valid": true
}
]
},
{
"description": "enum with [0] does not match [false]",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": [[0]]
},
"tests": [
{
"description": "[false] is invalid",
"data": [false],
"valid": false
},
{
"description": "[0] is valid",
"data": [0],
"valid": true
},
{
"description": "[0.0] is valid",
"data": [0.0],
"valid": true
}
]
},
{
"description": "enum with 1 does not match true",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": [1]
},
"tests": [
{
"description": "true is invalid",
"data": true,
"valid": false
},
{
"description": "integer one is valid",
"data": 1,
"valid": true
},
{
"description": "float one is valid",
"data": 1.0,
"valid": true
}
]
},
{
"description": "enum with [1] does not match [true]",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": [[1]]
},
"tests": [
{
"description": "[true] is invalid",
"data": [true],
"valid": false
},
{
"description": "[1] is valid",
"data": [1],
"valid": true
},
{
"description": "[1.0] is valid",
"data": [1.0],
"valid": true
}
]
},
{
"description": "nul characters in strings",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": [ "hello\u0000there" ]
},
"tests": [
{
"description": "match string with nul",
"data": "hello\u0000there",
"valid": true
},
{
"description": "do not match string lacking nul",
"data": "hellothere",
"valid": false
}
]
}
]
@@ -0,0 +1,31 @@
[
{
"description": "exclusiveMaximum validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"exclusiveMaximum": 3.0
},
"tests": [
{
"description": "below the exclusiveMaximum is valid",
"data": 2.2,
"valid": true
},
{
"description": "boundary point is invalid",
"data": 3.0,
"valid": false
},
{
"description": "above the exclusiveMaximum is invalid",
"data": 3.5,
"valid": false
},
{
"description": "ignores non-numbers",
"data": "x",
"valid": true
}
]
}
]
@@ -0,0 +1,31 @@
[
{
"description": "exclusiveMinimum validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"exclusiveMinimum": 1.1
},
"tests": [
{
"description": "above the exclusiveMinimum is valid",
"data": 1.2,
"valid": true
},
{
"description": "boundary point is invalid",
"data": 1.1,
"valid": false
},
{
"description": "below the exclusiveMinimum is invalid",
"data": 0.6,
"valid": false
},
{
"description": "ignores non-numbers",
"data": "x",
"valid": true
}
]
}
]
@@ -0,0 +1,838 @@
[
{
"description": "email format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "email"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid email string is only an annotation by default",
"data": "2962",
"valid": true
}
]
},
{
"description": "idn-email format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "idn-email"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid idn-email string is only an annotation by default",
"data": "2962",
"valid": true
}
]
},
{
"description": "regex format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "regex"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid regex string is only an annotation by default",
"data": "^(abc]",
"valid": true
}
]
},
{
"description": "ipv4 format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "ipv4"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid ipv4 string is only an annotation by default",
"data": "127.0.0.0.1",
"valid": true
}
]
},
{
"description": "ipv6 format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "ipv6"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid ipv6 string is only an annotation by default",
"data": "12345::",
"valid": true
}
]
},
{
"description": "idn-hostname format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "idn-hostname"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid idn-hostname string is only an annotation by default",
"data": "〮실례.테스트",
"valid": true
}
]
},
{
"description": "hostname format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "hostname"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid hostname string is only an annotation by default",
"data": "-a-host-name-that-starts-with--",
"valid": true
}
]
},
{
"description": "date format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "date"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid date string is only an annotation by default",
"data": "06/19/1963",
"valid": true
}
]
},
{
"description": "date-time format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "date-time"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid date-time string is only an annotation by default",
"data": "1990-02-31T15:59:60.123-08:00",
"valid": true
}
]
},
{
"description": "time format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "time"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid time string is only an annotation by default",
"data": "08:30:06 PST",
"valid": true
}
]
},
{
"description": "json-pointer format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "json-pointer"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid json-pointer string is only an annotation by default",
"data": "/foo/bar~",
"valid": true
}
]
},
{
"description": "relative-json-pointer format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "relative-json-pointer"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid relative-json-pointer string is only an annotation by default",
"data": "/foo/bar",
"valid": true
}
]
},
{
"description": "iri format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "iri"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid iri string is only an annotation by default",
"data": "http://2001:0db8:85a3:0000:0000:8a2e:0370:7334",
"valid": true
}
]
},
{
"description": "iri-reference format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "iri-reference"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid iri-reference string is only an annotation by default",
"data": "\\\\WINDOWS\\filëßåré",
"valid": true
}
]
},
{
"description": "uri format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "uri"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid uri string is only an annotation by default",
"data": "//foo.bar/?baz=qux#quux",
"valid": true
}
]
},
{
"description": "uri-reference format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "uri-reference"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid uri-reference string is only an annotation by default",
"data": "\\\\WINDOWS\\fileshare",
"valid": true
}
]
},
{
"description": "uri-template format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "uri-template"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid uri-template string is only an annotation by default",
"data": "http://example.com/dictionary/{term:1}/{term",
"valid": true
}
]
},
{
"description": "uuid format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "uuid"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid uuid string is only an annotation by default",
"data": "2eb8aa08-aa98-11ea-b4aa-73b441d1638",
"valid": true
}
]
},
{
"description": "duration format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "duration"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "invalid duration string is only an annotation by default",
"data": "PT1D",
"valid": true
}
]
}
]
@@ -0,0 +1,268 @@
[
{
"description": "ignore if without then or else",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"if": {
"const": 0
}
},
"tests": [
{
"description": "valid when valid against lone if",
"data": 0,
"valid": true
},
{
"description": "valid when invalid against lone if",
"data": "hello",
"valid": true
}
]
},
{
"description": "ignore then without if",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"then": {
"const": 0
}
},
"tests": [
{
"description": "valid when valid against lone then",
"data": 0,
"valid": true
},
{
"description": "valid when invalid against lone then",
"data": "hello",
"valid": true
}
]
},
{
"description": "ignore else without if",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"else": {
"const": 0
}
},
"tests": [
{
"description": "valid when valid against lone else",
"data": 0,
"valid": true
},
{
"description": "valid when invalid against lone else",
"data": "hello",
"valid": true
}
]
},
{
"description": "if and then without else",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"if": {
"exclusiveMaximum": 0
},
"then": {
"minimum": -10
}
},
"tests": [
{
"description": "valid through then",
"data": -1,
"valid": true
},
{
"description": "invalid through then",
"data": -100,
"valid": false
},
{
"description": "valid when if test fails",
"data": 3,
"valid": true
}
]
},
{
"description": "if and else without then",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"if": {
"exclusiveMaximum": 0
},
"else": {
"multipleOf": 2
}
},
"tests": [
{
"description": "valid when if test passes",
"data": -1,
"valid": true
},
{
"description": "valid through else",
"data": 4,
"valid": true
},
{
"description": "invalid through else",
"data": 3,
"valid": false
}
]
},
{
"description": "validate against correct branch, then vs else",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"if": {
"exclusiveMaximum": 0
},
"then": {
"minimum": -10
},
"else": {
"multipleOf": 2
}
},
"tests": [
{
"description": "valid through then",
"data": -1,
"valid": true
},
{
"description": "invalid through then",
"data": -100,
"valid": false
},
{
"description": "valid through else",
"data": 4,
"valid": true
},
{
"description": "invalid through else",
"data": 3,
"valid": false
}
]
},
{
"description": "non-interference across combined schemas",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{
"if": {
"exclusiveMaximum": 0
}
},
{
"then": {
"minimum": -10
}
},
{
"else": {
"multipleOf": 2
}
}
]
},
"tests": [
{
"description": "valid, but would have been invalid through then",
"data": -100,
"valid": true
},
{
"description": "valid, but would have been invalid through else",
"data": 3,
"valid": true
}
]
},
{
"description": "if with boolean schema true",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"if": true,
"then": { "const": "then" },
"else": { "const": "else" }
},
"tests": [
{
"description": "boolean schema true in if always chooses the then path (valid)",
"data": "then",
"valid": true
},
{
"description": "boolean schema true in if always chooses the then path (invalid)",
"data": "else",
"valid": false
}
]
},
{
"description": "if with boolean schema false",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"if": false,
"then": { "const": "then" },
"else": { "const": "else" }
},
"tests": [
{
"description": "boolean schema false in if always chooses the else path (invalid)",
"data": "then",
"valid": false
},
{
"description": "boolean schema false in if always chooses the else path (valid)",
"data": "else",
"valid": true
}
]
},
{
"description": "if appears at the end when serialized (keyword processing sequence)",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"then": { "const": "yes" },
"else": { "const": "other" },
"if": { "maxLength": 4 }
},
"tests": [
{
"description": "yes redirects to then and passes",
"data": "yes",
"valid": true
},
{
"description": "other redirects to else and passes",
"data": "other",
"valid": true
},
{
"description": "no redirects to then and fails",
"data": "no",
"valid": false
},
{
"description": "invalid redirects to else and fails",
"data": "invalid",
"valid": false
}
]
}
]
@@ -0,0 +1,37 @@
[
{
"description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$defs": {
"int": { "type": "integer" }
},
"allOf": [
{
"properties": {
"foo": {
"$ref": "#/$defs/int"
}
}
},
{
"additionalProperties": {
"$ref": "#/$defs/int"
}
}
]
},
"tests": [
{
"description": "passing case",
"data": { "foo": 1 },
"valid": true
},
{
"description": "failing case",
"data": { "foo": "a string" },
"valid": false
}
]
}
]
@@ -0,0 +1,304 @@
[
{
"description": "a schema given for items",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"items": {"type": "integer"}
},
"tests": [
{
"description": "valid items",
"data": [ 1, 2, 3 ],
"valid": true
},
{
"description": "wrong type of items",
"data": [1, "x"],
"valid": false
},
{
"description": "ignores non-arrays",
"data": {"foo" : "bar"},
"valid": true
},
{
"description": "JavaScript pseudo-array is valid",
"data": {
"0": "invalid",
"length": 1
},
"valid": true
}
]
},
{
"description": "items with boolean schema (true)",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"items": true
},
"tests": [
{
"description": "any array is valid",
"data": [ 1, "foo", true ],
"valid": true
},
{
"description": "empty array is valid",
"data": [],
"valid": true
}
]
},
{
"description": "items with boolean schema (false)",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"items": false
},
"tests": [
{
"description": "any non-empty array is invalid",
"data": [ 1, "foo", true ],
"valid": false
},
{
"description": "empty array is valid",
"data": [],
"valid": true
}
]
},
{
"description": "items and subitems",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$defs": {
"item": {
"type": "array",
"items": false,
"prefixItems": [
{ "$ref": "#/$defs/sub-item" },
{ "$ref": "#/$defs/sub-item" }
]
},
"sub-item": {
"type": "object",
"required": ["foo"]
}
},
"type": "array",
"items": false,
"prefixItems": [
{ "$ref": "#/$defs/item" },
{ "$ref": "#/$defs/item" },
{ "$ref": "#/$defs/item" }
]
},
"tests": [
{
"description": "valid items",
"data": [
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ]
],
"valid": true
},
{
"description": "too many items",
"data": [
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ]
],
"valid": false
},
{
"description": "too many sub-items",
"data": [
[ {"foo": null}, {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ]
],
"valid": false
},
{
"description": "wrong item",
"data": [
{"foo": null},
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ]
],
"valid": false
},
{
"description": "wrong sub-item",
"data": [
[ {}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ]
],
"valid": false
},
{
"description": "fewer items is valid",
"data": [
[ {"foo": null} ],
[ {"foo": null} ]
],
"valid": true
}
]
},
{
"description": "nested items",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"items": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "number"
}
}
}
}
},
"tests": [
{
"description": "valid nested array",
"data": [[[[1]], [[2],[3]]], [[[4], [5], [6]]]],
"valid": true
},
{
"description": "nested array with invalid type",
"data": [[[["1"]], [[2],[3]]], [[[4], [5], [6]]]],
"valid": false
},
{
"description": "not deep enough",
"data": [[[1], [2],[3]], [[4], [5], [6]]],
"valid": false
}
]
},
{
"description": "prefixItems with no additional items allowed",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [{}, {}, {}],
"items": false
},
"tests": [
{
"description": "empty array",
"data": [ ],
"valid": true
},
{
"description": "fewer number of items present (1)",
"data": [ 1 ],
"valid": true
},
{
"description": "fewer number of items present (2)",
"data": [ 1, 2 ],
"valid": true
},
{
"description": "equal number of items present",
"data": [ 1, 2, 3 ],
"valid": true
},
{
"description": "additional items are not permitted",
"data": [ 1, 2, 3, 4 ],
"valid": false
}
]
},
{
"description": "items does not look in applicators, valid case",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{ "prefixItems": [ { "minimum": 3 } ] }
],
"items": { "minimum": 5 }
},
"tests": [
{
"description": "prefixItems in allOf does not constrain items, invalid case",
"data": [ 3, 5 ],
"valid": false
},
{
"description": "prefixItems in allOf does not constrain items, valid case",
"data": [ 5, 5 ],
"valid": true
}
]
},
{
"description": "prefixItems validation adjusts the starting index for items",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [ { "type": "string" } ],
"items": { "type": "integer" }
},
"tests": [
{
"description": "valid items",
"data": [ "x", 2, 3 ],
"valid": true
},
{
"description": "wrong type of second item",
"data": [ "x", "y" ],
"valid": false
}
]
},
{
"description": "items with heterogeneous array",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [{}],
"items": false
},
"tests": [
{
"description": "heterogeneous invalid instance",
"data": [ "foo", "bar", 37 ],
"valid": false
},
{
"description": "valid instance",
"data": [ null ],
"valid": true
}
]
},
{
"description": "items with null instance elements",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"items": {
"type": "null"
}
},
"tests": [
{
"description": "allows null elements",
"data": [ null ],
"valid": true
}
]
}
]
@@ -0,0 +1,102 @@
[
{
"description": "maxContains without contains is ignored",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"maxContains": 1
},
"tests": [
{
"description": "one item valid against lone maxContains",
"data": [ 1 ],
"valid": true
},
{
"description": "two items still valid against lone maxContains",
"data": [ 1, 2 ],
"valid": true
}
]
},
{
"description": "maxContains with contains",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {"const": 1},
"maxContains": 1
},
"tests": [
{
"description": "empty data",
"data": [ ],
"valid": false
},
{
"description": "all elements match, valid maxContains",
"data": [ 1 ],
"valid": true
},
{
"description": "all elements match, invalid maxContains",
"data": [ 1, 1 ],
"valid": false
},
{
"description": "some elements match, valid maxContains",
"data": [ 1, 2 ],
"valid": true
},
{
"description": "some elements match, invalid maxContains",
"data": [ 1, 2, 1 ],
"valid": false
}
]
},
{
"description": "maxContains with contains, value with a decimal",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {"const": 1},
"maxContains": 1.0
},
"tests": [
{
"description": "one element matches, valid maxContains",
"data": [ 1 ],
"valid": true
},
{
"description": "too many elements match, invalid maxContains",
"data": [ 1, 1 ],
"valid": false
}
]
},
{
"description": "minContains < maxContains",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {"const": 1},
"minContains": 1,
"maxContains": 3
},
"tests": [
{
"description": "actual < minContains < maxContains",
"data": [ ],
"valid": false
},
{
"description": "minContains < actual < maxContains",
"data": [ 1, 1 ],
"valid": true
},
{
"description": "minContains < maxContains < actual",
"data": [ 1, 1, 1, 1 ],
"valid": false
}
]
}
]
@@ -0,0 +1,50 @@
[
{
"description": "maxItems validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"maxItems": 2
},
"tests": [
{
"description": "shorter is valid",
"data": [1],
"valid": true
},
{
"description": "exact length is valid",
"data": [1, 2],
"valid": true
},
{
"description": "too long is invalid",
"data": [1, 2, 3],
"valid": false
},
{
"description": "ignores non-arrays",
"data": "foobar",
"valid": true
}
]
},
{
"description": "maxItems validation with a decimal",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"maxItems": 2.0
},
"tests": [
{
"description": "shorter is valid",
"data": [1],
"valid": true
},
{
"description": "too long is invalid",
"data": [1, 2, 3],
"valid": false
}
]
}
]
@@ -0,0 +1,55 @@
[
{
"description": "maxLength validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"maxLength": 2
},
"tests": [
{
"description": "shorter is valid",
"data": "f",
"valid": true
},
{
"description": "exact length is valid",
"data": "fo",
"valid": true
},
{
"description": "too long is invalid",
"data": "foo",
"valid": false
},
{
"description": "ignores non-strings",
"data": 100,
"valid": true
},
{
"description": "two graphemes is long enough",
"data": "\uD83D\uDCA9\uD83D\uDCA9",
"valid": true
}
]
},
{
"description": "maxLength validation with a decimal",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"maxLength": 2.0
},
"tests": [
{
"description": "shorter is valid",
"data": "f",
"valid": true
},
{
"description": "too long is invalid",
"data": "foo",
"valid": false
}
]
}
]
@@ -0,0 +1,79 @@
[
{
"description": "maxProperties validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"maxProperties": 2
},
"tests": [
{
"description": "shorter is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "exact length is valid",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "too long is invalid",
"data": {"foo": 1, "bar": 2, "baz": 3},
"valid": false
},
{
"description": "ignores arrays",
"data": [1, 2, 3],
"valid": true
},
{
"description": "ignores strings",
"data": "foobar",
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
}
]
},
{
"description": "maxProperties validation with a decimal",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"maxProperties": 2.0
},
"tests": [
{
"description": "shorter is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "too long is invalid",
"data": {"foo": 1, "bar": 2, "baz": 3},
"valid": false
}
]
},
{
"description": "maxProperties = 0 means the object is empty",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"maxProperties": 0
},
"tests": [
{
"description": "no properties is valid",
"data": {},
"valid": true
},
{
"description": "one property is invalid",
"data": { "foo": 1 },
"valid": false
}
]
}
]
@@ -0,0 +1,60 @@
[
{
"description": "maximum validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"maximum": 3.0
},
"tests": [
{
"description": "below the maximum is valid",
"data": 2.6,
"valid": true
},
{
"description": "boundary point is valid",
"data": 3.0,
"valid": true
},
{
"description": "above the maximum is invalid",
"data": 3.5,
"valid": false
},
{
"description": "ignores non-numbers",
"data": "x",
"valid": true
}
]
},
{
"description": "maximum validation with unsigned integer",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"maximum": 300
},
"tests": [
{
"description": "below the maximum is invalid",
"data": 299.97,
"valid": true
},
{
"description": "boundary point integer is valid",
"data": 300,
"valid": true
},
{
"description": "boundary point float is valid",
"data": 300.00,
"valid": true
},
{
"description": "above the maximum is invalid",
"data": 300.5,
"valid": false
}
]
}
]
@@ -0,0 +1,224 @@
[
{
"description": "minContains without contains is ignored",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"minContains": 1
},
"tests": [
{
"description": "one item valid against lone minContains",
"data": [ 1 ],
"valid": true
},
{
"description": "zero items still valid against lone minContains",
"data": [],
"valid": true
}
]
},
{
"description": "minContains=1 with contains",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {"const": 1},
"minContains": 1
},
"tests": [
{
"description": "empty data",
"data": [ ],
"valid": false
},
{
"description": "no elements match",
"data": [ 2 ],
"valid": false
},
{
"description": "single element matches, valid minContains",
"data": [ 1 ],
"valid": true
},
{
"description": "some elements match, valid minContains",
"data": [ 1, 2 ],
"valid": true
},
{
"description": "all elements match, valid minContains",
"data": [ 1, 1 ],
"valid": true
}
]
},
{
"description": "minContains=2 with contains",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {"const": 1},
"minContains": 2
},
"tests": [
{
"description": "empty data",
"data": [ ],
"valid": false
},
{
"description": "all elements match, invalid minContains",
"data": [ 1 ],
"valid": false
},
{
"description": "some elements match, invalid minContains",
"data": [ 1, 2 ],
"valid": false
},
{
"description": "all elements match, valid minContains (exactly as needed)",
"data": [ 1, 1 ],
"valid": true
},
{
"description": "all elements match, valid minContains (more than needed)",
"data": [ 1, 1, 1 ],
"valid": true
},
{
"description": "some elements match, valid minContains",
"data": [ 1, 2, 1 ],
"valid": true
}
]
},
{
"description": "minContains=2 with contains with a decimal value",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {"const": 1},
"minContains": 2.0
},
"tests": [
{
"description": "one element matches, invalid minContains",
"data": [ 1 ],
"valid": false
},
{
"description": "both elements match, valid minContains",
"data": [ 1, 1 ],
"valid": true
}
]
},
{
"description": "maxContains = minContains",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {"const": 1},
"maxContains": 2,
"minContains": 2
},
"tests": [
{
"description": "empty data",
"data": [ ],
"valid": false
},
{
"description": "all elements match, invalid minContains",
"data": [ 1 ],
"valid": false
},
{
"description": "all elements match, invalid maxContains",
"data": [ 1, 1, 1 ],
"valid": false
},
{
"description": "all elements match, valid maxContains and minContains",
"data": [ 1, 1 ],
"valid": true
}
]
},
{
"description": "maxContains < minContains",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {"const": 1},
"maxContains": 1,
"minContains": 3
},
"tests": [
{
"description": "empty data",
"data": [ ],
"valid": false
},
{
"description": "invalid minContains",
"data": [ 1 ],
"valid": false
},
{
"description": "invalid maxContains",
"data": [ 1, 1, 1 ],
"valid": false
},
{
"description": "invalid maxContains and minContains",
"data": [ 1, 1 ],
"valid": false
}
]
},
{
"description": "minContains = 0",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {"const": 1},
"minContains": 0
},
"tests": [
{
"description": "empty data",
"data": [ ],
"valid": true
},
{
"description": "minContains = 0 makes contains always pass",
"data": [ 2 ],
"valid": true
}
]
},
{
"description": "minContains = 0 with maxContains",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {"const": 1},
"minContains": 0,
"maxContains": 1
},
"tests": [
{
"description": "empty data",
"data": [ ],
"valid": true
},
{
"description": "not more than maxContains",
"data": [ 1 ],
"valid": true
},
{
"description": "too many",
"data": [ 1, 1 ],
"valid": false
}
]
}
]
@@ -0,0 +1,50 @@
[
{
"description": "minItems validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"minItems": 1
},
"tests": [
{
"description": "longer is valid",
"data": [1, 2],
"valid": true
},
{
"description": "exact length is valid",
"data": [1],
"valid": true
},
{
"description": "too short is invalid",
"data": [],
"valid": false
},
{
"description": "ignores non-arrays",
"data": "",
"valid": true
}
]
},
{
"description": "minItems validation with a decimal",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"minItems": 1.0
},
"tests": [
{
"description": "longer is valid",
"data": [1, 2],
"valid": true
},
{
"description": "too short is invalid",
"data": [],
"valid": false
}
]
}
]
@@ -0,0 +1,55 @@
[
{
"description": "minLength validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"minLength": 2
},
"tests": [
{
"description": "longer is valid",
"data": "foo",
"valid": true
},
{
"description": "exact length is valid",
"data": "fo",
"valid": true
},
{
"description": "too short is invalid",
"data": "f",
"valid": false
},
{
"description": "ignores non-strings",
"data": 1,
"valid": true
},
{
"description": "one grapheme is not long enough",
"data": "\uD83D\uDCA9",
"valid": false
}
]
},
{
"description": "minLength validation with a decimal",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"minLength": 2.0
},
"tests": [
{
"description": "longer is valid",
"data": "foo",
"valid": true
},
{
"description": "too short is invalid",
"data": "f",
"valid": false
}
]
}
]
@@ -0,0 +1,60 @@
[
{
"description": "minProperties validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"minProperties": 1
},
"tests": [
{
"description": "longer is valid",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "exact length is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "too short is invalid",
"data": {},
"valid": false
},
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores strings",
"data": "",
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
}
]
},
{
"description": "minProperties validation with a decimal",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"minProperties": 1.0
},
"tests": [
{
"description": "longer is valid",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "too short is invalid",
"data": {},
"valid": false
}
]
}
]
@@ -0,0 +1,75 @@
[
{
"description": "minimum validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"minimum": 1.1
},
"tests": [
{
"description": "above the minimum is valid",
"data": 2.6,
"valid": true
},
{
"description": "boundary point is valid",
"data": 1.1,
"valid": true
},
{
"description": "below the minimum is invalid",
"data": 0.6,
"valid": false
},
{
"description": "ignores non-numbers",
"data": "x",
"valid": true
}
]
},
{
"description": "minimum validation with signed integer",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"minimum": -2
},
"tests": [
{
"description": "negative above the minimum is valid",
"data": -1,
"valid": true
},
{
"description": "positive above the minimum is valid",
"data": 0,
"valid": true
},
{
"description": "boundary point is valid",
"data": -2,
"valid": true
},
{
"description": "boundary point with float is valid",
"data": -2.0,
"valid": true
},
{
"description": "float below the minimum is invalid",
"data": -2.0001,
"valid": false
},
{
"description": "int below the minimum is invalid",
"data": -3,
"valid": false
},
{
"description": "ignores non-numbers",
"data": "x",
"valid": true
}
]
}
]
@@ -0,0 +1,97 @@
[
{
"description": "by int",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"multipleOf": 2
},
"tests": [
{
"description": "int by int",
"data": 10,
"valid": true
},
{
"description": "int by int fail",
"data": 7,
"valid": false
},
{
"description": "ignores non-numbers",
"data": "foo",
"valid": true
}
]
},
{
"description": "by number",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"multipleOf": 1.5
},
"tests": [
{
"description": "zero is multiple of anything",
"data": 0,
"valid": true
},
{
"description": "4.5 is multiple of 1.5",
"data": 4.5,
"valid": true
},
{
"description": "35 is not multiple of 1.5",
"data": 35,
"valid": false
}
]
},
{
"description": "by small number",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"multipleOf": 0.0001
},
"tests": [
{
"description": "0.0075 is multiple of 0.0001",
"data": 0.0075,
"valid": true
},
{
"description": "0.00751 is not multiple of 0.0001",
"data": 0.00751,
"valid": false
}
]
},
{
"description": "float division = inf",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "integer", "multipleOf": 0.123456789
},
"tests": [
{
"description": "always invalid, but naive implementations may raise an overflow error",
"data": 1e308,
"valid": false
}
]
},
{
"description": "small multiple of large integer",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "integer", "multipleOf": 1e-8
},
"tests": [
{
"description": "any integer is a multiple of 1e-8",
"data": 12391239123,
"valid": true
}
]
}
]
@@ -0,0 +1,301 @@
[
{
"description": "not",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"not": {"type": "integer"}
},
"tests": [
{
"description": "allowed",
"data": "foo",
"valid": true
},
{
"description": "disallowed",
"data": 1,
"valid": false
}
]
},
{
"description": "not multiple types",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"not": {"type": ["integer", "boolean"]}
},
"tests": [
{
"description": "valid",
"data": "foo",
"valid": true
},
{
"description": "mismatch",
"data": 1,
"valid": false
},
{
"description": "other mismatch",
"data": true,
"valid": false
}
]
},
{
"description": "not more complex schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"not": {
"type": "object",
"properties": {
"foo": {
"type": "string"
}
}
}
},
"tests": [
{
"description": "match",
"data": 1,
"valid": true
},
{
"description": "other match",
"data": {"foo": 1},
"valid": true
},
{
"description": "mismatch",
"data": {"foo": "bar"},
"valid": false
}
]
},
{
"description": "forbidden property",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": {
"not": {}
}
}
},
"tests": [
{
"description": "property present",
"data": {"foo": 1, "bar": 2},
"valid": false
},
{
"description": "property absent",
"data": {"bar": 1, "baz": 2},
"valid": true
}
]
},
{
"description": "forbid everything with empty schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"not": {}
},
"tests": [
{
"description": "number is invalid",
"data": 1,
"valid": false
},
{
"description": "string is invalid",
"data": "foo",
"valid": false
},
{
"description": "boolean true is invalid",
"data": true,
"valid": false
},
{
"description": "boolean false is invalid",
"data": false,
"valid": false
},
{
"description": "null is invalid",
"data": null,
"valid": false
},
{
"description": "object is invalid",
"data": {"foo": "bar"},
"valid": false
},
{
"description": "empty object is invalid",
"data": {},
"valid": false
},
{
"description": "array is invalid",
"data": ["foo"],
"valid": false
},
{
"description": "empty array is invalid",
"data": [],
"valid": false
}
]
},
{
"description": "forbid everything with boolean schema true",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"not": true
},
"tests": [
{
"description": "number is invalid",
"data": 1,
"valid": false
},
{
"description": "string is invalid",
"data": "foo",
"valid": false
},
{
"description": "boolean true is invalid",
"data": true,
"valid": false
},
{
"description": "boolean false is invalid",
"data": false,
"valid": false
},
{
"description": "null is invalid",
"data": null,
"valid": false
},
{
"description": "object is invalid",
"data": {"foo": "bar"},
"valid": false
},
{
"description": "empty object is invalid",
"data": {},
"valid": false
},
{
"description": "array is invalid",
"data": ["foo"],
"valid": false
},
{
"description": "empty array is invalid",
"data": [],
"valid": false
}
]
},
{
"description": "allow everything with boolean schema false",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"not": false
},
"tests": [
{
"description": "number is valid",
"data": 1,
"valid": true
},
{
"description": "string is valid",
"data": "foo",
"valid": true
},
{
"description": "boolean true is valid",
"data": true,
"valid": true
},
{
"description": "boolean false is valid",
"data": false,
"valid": true
},
{
"description": "null is valid",
"data": null,
"valid": true
},
{
"description": "object is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "empty object is valid",
"data": {},
"valid": true
},
{
"description": "array is valid",
"data": ["foo"],
"valid": true
},
{
"description": "empty array is valid",
"data": [],
"valid": true
}
]
},
{
"description": "double negation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"not": { "not": {} }
},
"tests": [
{
"description": "any value is valid",
"data": "foo",
"valid": true
}
]
},
{
"description": "collect annotations inside a 'not', even if collection is disabled",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"not": {
"$comment": "this subschema must still produce annotations internally, even though the 'not' will ultimately discard them",
"anyOf": [
true,
{ "properties": { "foo": true } }
],
"unevaluatedProperties": false
}
},
"tests": [
{
"description": "unevaluated property",
"data": { "bar": 1 },
"valid": true
},
{
"description": "annotations are still collected inside a 'not'",
"data": { "foo": 1 },
"valid": false
}
]
}
]
@@ -0,0 +1,293 @@
[
{
"description": "oneOf",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"oneOf": [
{
"type": "integer"
},
{
"minimum": 2
}
]
},
"tests": [
{
"description": "first oneOf valid",
"data": 1,
"valid": true
},
{
"description": "second oneOf valid",
"data": 2.5,
"valid": true
},
{
"description": "both oneOf valid",
"data": 3,
"valid": false
},
{
"description": "neither oneOf valid",
"data": 1.5,
"valid": false
}
]
},
{
"description": "oneOf with base schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"oneOf" : [
{
"minLength": 2
},
{
"maxLength": 4
}
]
},
"tests": [
{
"description": "mismatch base schema",
"data": 3,
"valid": false
},
{
"description": "one oneOf valid",
"data": "foobar",
"valid": true
},
{
"description": "both oneOf valid",
"data": "foo",
"valid": false
}
]
},
{
"description": "oneOf with boolean schemas, all true",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"oneOf": [true, true, true]
},
"tests": [
{
"description": "any value is invalid",
"data": "foo",
"valid": false
}
]
},
{
"description": "oneOf with boolean schemas, one true",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"oneOf": [true, false, false]
},
"tests": [
{
"description": "any value is valid",
"data": "foo",
"valid": true
}
]
},
{
"description": "oneOf with boolean schemas, more than one true",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"oneOf": [true, true, false]
},
"tests": [
{
"description": "any value is invalid",
"data": "foo",
"valid": false
}
]
},
{
"description": "oneOf with boolean schemas, all false",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"oneOf": [false, false, false]
},
"tests": [
{
"description": "any value is invalid",
"data": "foo",
"valid": false
}
]
},
{
"description": "oneOf complex types",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"oneOf": [
{
"properties": {
"bar": {"type": "integer"}
},
"required": ["bar"]
},
{
"properties": {
"foo": {"type": "string"}
},
"required": ["foo"]
}
]
},
"tests": [
{
"description": "first oneOf valid (complex)",
"data": {"bar": 2},
"valid": true
},
{
"description": "second oneOf valid (complex)",
"data": {"foo": "baz"},
"valid": true
},
{
"description": "both oneOf valid (complex)",
"data": {"foo": "baz", "bar": 2},
"valid": false
},
{
"description": "neither oneOf valid (complex)",
"data": {"foo": 2, "bar": "quux"},
"valid": false
}
]
},
{
"description": "oneOf with empty schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"oneOf": [
{ "type": "number" },
{}
]
},
"tests": [
{
"description": "one valid - valid",
"data": "foo",
"valid": true
},
{
"description": "both valid - invalid",
"data": 123,
"valid": false
}
]
},
{
"description": "oneOf with required",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"oneOf": [
{ "required": ["foo", "bar"] },
{ "required": ["foo", "baz"] }
]
},
"tests": [
{
"description": "both invalid - invalid",
"data": {"bar": 2},
"valid": false
},
{
"description": "first valid - valid",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "second valid - valid",
"data": {"foo": 1, "baz": 3},
"valid": true
},
{
"description": "both valid - invalid",
"data": {"foo": 1, "bar": 2, "baz" : 3},
"valid": false
}
]
},
{
"description": "oneOf with missing optional property",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"oneOf": [
{
"properties": {
"bar": true,
"baz": true
},
"required": ["bar"]
},
{
"properties": {
"foo": true
},
"required": ["foo"]
}
]
},
"tests": [
{
"description": "first oneOf valid",
"data": {"bar": 8},
"valid": true
},
{
"description": "second oneOf valid",
"data": {"foo": "foo"},
"valid": true
},
{
"description": "both oneOf valid",
"data": {"foo": "foo", "bar": 8},
"valid": false
},
{
"description": "neither oneOf valid",
"data": {"baz": "quux"},
"valid": false
}
]
},
{
"description": "nested oneOf, to check validation semantics",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"oneOf": [
{
"oneOf": [
{
"type": "null"
}
]
}
]
},
"tests": [
{
"description": "null is valid",
"data": null,
"valid": true
},
{
"description": "anything non-null is invalid",
"data": 123,
"valid": false
}
]
}
]
@@ -0,0 +1,60 @@
[
{
"description": "$anchor inside an enum is not a real identifier",
"comment": "the implementation must not be confused by an $anchor buried in the enum",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$defs": {
"anchor_in_enum": {
"enum": [
{
"$anchor": "my_anchor",
"type": "null"
}
]
},
"real_identifier_in_schema": {
"$anchor": "my_anchor",
"type": "string"
},
"zzz_anchor_in_const": {
"const": {
"$anchor": "my_anchor",
"type": "null"
}
}
},
"anyOf": [
{ "$ref": "#/$defs/anchor_in_enum" },
{ "$ref": "#my_anchor" }
]
},
"tests": [
{
"description": "exact match to enum, and type matches",
"data": {
"$anchor": "my_anchor",
"type": "null"
},
"valid": true
},
{
"description": "in implementations that strip $anchor, this may match either $def",
"data": {
"type": "null"
},
"valid": false
},
{
"description": "match $ref to $anchor",
"data": "a string to match #/$defs/anchor_in_enum",
"valid": true
},
{
"description": "no match on enum or $ref to $anchor",
"data": 1,
"valid": false
}
]
}
]
@@ -0,0 +1,110 @@
[
{
"description": "integer",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "integer"
},
"tests": [
{
"description": "a bignum is an integer",
"data": 12345678910111213141516171819202122232425262728293031,
"valid": true
},
{
"description": "a negative bignum is an integer",
"data": -12345678910111213141516171819202122232425262728293031,
"valid": true
}
]
},
{
"description": "number",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "number"
},
"tests": [
{
"description": "a bignum is a number",
"data": 98249283749234923498293171823948729348710298301928331,
"valid": true
},
{
"description": "a negative bignum is a number",
"data": -98249283749234923498293171823948729348710298301928331,
"valid": true
}
]
},
{
"description": "string",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string"
},
"tests": [
{
"description": "a bignum is not a string",
"data": 98249283749234923498293171823948729348710298301928331,
"valid": false
}
]
},
{
"description": "maximum integer comparison",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"maximum": 18446744073709551615
},
"tests": [
{
"description": "comparison works for high numbers",
"data": 18446744073709551600,
"valid": true
}
]
},
{
"description": "float comparison with high precision",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"exclusiveMaximum": 972783798187987123879878123.18878137
},
"tests": [
{
"description": "comparison works for high numbers",
"data": 972783798187987123879878123.188781371,
"valid": false
}
]
},
{
"description": "minimum integer comparison",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"minimum": -18446744073709551615
},
"tests": [
{
"description": "comparison works for very negative numbers",
"data": -18446744073709551600,
"valid": true
}
]
},
{
"description": "float comparison with high precision on negative numbers",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"exclusiveMinimum": -972783798187987123879878123.18878137
},
"tests": [
{
"description": "comparison works for very negative numbers",
"data": -972783798187987123879878123.188781371,
"valid": false
}
]
}
]
@@ -0,0 +1,18 @@
[
{
"description": "refs to historic drafts are processed as historic drafts",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"$ref": "http://localhost:1234/draft2019-09/ignore-prefixItems.json"
},
"tests": [
{
"description": "first item not a string is valid",
"comment": "if the implementation is not processing the $ref as a 2019-09 schema, this test will fail",
"data": [1, 2, 3],
"valid": true
}
]
}
]
@@ -0,0 +1,282 @@
[
{
"description": "single dependency",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependencies": {"bar": ["foo"]}
},
"tests": [
{
"description": "neither",
"data": {},
"valid": true
},
{
"description": "nondependant",
"data": {"foo": 1},
"valid": true
},
{
"description": "with dependency",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "missing dependency",
"data": {"bar": 2},
"valid": false
},
{
"description": "ignores arrays",
"data": ["bar"],
"valid": true
},
{
"description": "ignores strings",
"data": "foobar",
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
}
]
},
{
"description": "empty dependents",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependencies": {"bar": []}
},
"tests": [
{
"description": "empty object",
"data": {},
"valid": true
},
{
"description": "object with one property",
"data": {"bar": 2},
"valid": true
},
{
"description": "non-object is valid",
"data": 1,
"valid": true
}
]
},
{
"description": "multiple dependents required",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependencies": {"quux": ["foo", "bar"]}
},
"tests": [
{
"description": "neither",
"data": {},
"valid": true
},
{
"description": "nondependants",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "with dependencies",
"data": {"foo": 1, "bar": 2, "quux": 3},
"valid": true
},
{
"description": "missing dependency",
"data": {"foo": 1, "quux": 2},
"valid": false
},
{
"description": "missing other dependency",
"data": {"bar": 1, "quux": 2},
"valid": false
},
{
"description": "missing both dependencies",
"data": {"quux": 1},
"valid": false
}
]
},
{
"description": "dependencies with escaped characters",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependencies": {
"foo\nbar": ["foo\rbar"],
"foo\"bar": ["foo'bar"]
}
},
"tests": [
{
"description": "CRLF",
"data": {
"foo\nbar": 1,
"foo\rbar": 2
},
"valid": true
},
{
"description": "quoted quotes",
"data": {
"foo'bar": 1,
"foo\"bar": 2
},
"valid": true
},
{
"description": "CRLF missing dependent",
"data": {
"foo\nbar": 1,
"foo": 2
},
"valid": false
},
{
"description": "quoted quotes missing dependent",
"data": {
"foo\"bar": 2
},
"valid": false
}
]
},
{
"description": "single schema dependency",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependencies": {
"bar": {
"properties": {
"foo": {"type": "integer"},
"bar": {"type": "integer"}
}
}
}
},
"tests": [
{
"description": "valid",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "no dependency",
"data": {"foo": "quux"},
"valid": true
},
{
"description": "wrong type",
"data": {"foo": "quux", "bar": 2},
"valid": false
},
{
"description": "wrong type other",
"data": {"foo": 2, "bar": "quux"},
"valid": false
},
{
"description": "wrong type both",
"data": {"foo": "quux", "bar": "quux"},
"valid": false
},
{
"description": "ignores arrays",
"data": ["bar"],
"valid": true
},
{
"description": "ignores strings",
"data": "foobar",
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
}
]
},
{
"description": "boolean subschemas",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependencies": {
"foo": true,
"bar": false
}
},
"tests": [
{
"description": "object with property having schema true is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "object with property having schema false is invalid",
"data": {"bar": 2},
"valid": false
},
{
"description": "object with both properties is invalid",
"data": {"foo": 1, "bar": 2},
"valid": false
},
{
"description": "empty object is valid",
"data": {},
"valid": true
}
]
},
{
"description": "schema dependencies with escaped characters",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"dependencies": {
"foo\tbar": {"minProperties": 4},
"foo'bar": {"required": ["foo\"bar"]}
}
},
"tests": [
{
"description": "quoted tab",
"data": {
"foo\tbar": 1,
"a": 2,
"b": 3,
"c": 4
},
"valid": true
},
{
"description": "quoted quote",
"data": {
"foo'bar": {"foo\"bar": 1}
},
"valid": false
},
{
"description": "quoted tab invalid under dependent schema",
"data": {
"foo\tbar": 1,
"a": 2
},
"valid": false
},
{
"description": "quoted quote invalid under dependent schema",
"data": {"foo'bar": 1},
"valid": false
}
]
}
]
@@ -0,0 +1,56 @@
[
{
"description": "$dynamicRef skips over intermediate resources - pointer reference across resource boundary",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/optional/main",
"type": "object",
"properties": {
"bar-item": {
"$ref": "bar#/$defs/item"
}
},
"$defs": {
"bar": {
"$id": "bar",
"type": "array",
"items": {
"$ref": "item"
},
"$defs": {
"item": {
"$id": "item",
"type": "object",
"properties": {
"content": {
"$dynamicRef": "#content"
}
},
"$defs": {
"defaultContent": {
"$dynamicAnchor": "content",
"type": "integer"
}
}
},
"content": {
"$dynamicAnchor": "content",
"type": "string"
}
}
}
}
},
"tests": [
{
"description": "integer property passes",
"data": { "bar-item": { "content": 42 } },
"valid": true
},
{
"description": "string property fails",
"data": { "bar-item": { "content": "value" } },
"valid": false
}
]
}]
@@ -0,0 +1,582 @@
[
{
"description": "ECMA 262 regex $ does not match trailing newline",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"pattern": "^abc$"
},
"tests": [
{
"description": "matches in Python, but not in ECMA 262",
"data": "abc\\n",
"valid": false
},
{
"description": "matches",
"data": "abc",
"valid": true
}
]
},
{
"description": "ECMA 262 regex converts \\t to horizontal tab",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"pattern": "^\\t$"
},
"tests": [
{
"description": "does not match",
"data": "\\t",
"valid": false
},
{
"description": "matches",
"data": "\u0009",
"valid": true
}
]
},
{
"description": "ECMA 262 regex escapes control codes with \\c and upper letter",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"pattern": "^\\cC$"
},
"tests": [
{
"description": "does not match",
"data": "\\cC",
"valid": false
},
{
"description": "matches",
"data": "\u0003",
"valid": true
}
]
},
{
"description": "ECMA 262 regex escapes control codes with \\c and lower letter",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"pattern": "^\\cc$"
},
"tests": [
{
"description": "does not match",
"data": "\\cc",
"valid": false
},
{
"description": "matches",
"data": "\u0003",
"valid": true
}
]
},
{
"description": "ECMA 262 \\d matches ascii digits only",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"pattern": "^\\d$"
},
"tests": [
{
"description": "ASCII zero matches",
"data": "0",
"valid": true
},
{
"description": "NKO DIGIT ZERO does not match (unlike e.g. Python)",
"data": "߀",
"valid": false
},
{
"description": "NKO DIGIT ZERO (as \\u escape) does not match",
"data": "\u07c0",
"valid": false
}
]
},
{
"description": "ECMA 262 \\D matches everything but ascii digits",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"pattern": "^\\D$"
},
"tests": [
{
"description": "ASCII zero does not match",
"data": "0",
"valid": false
},
{
"description": "NKO DIGIT ZERO matches (unlike e.g. Python)",
"data": "߀",
"valid": true
},
{
"description": "NKO DIGIT ZERO (as \\u escape) matches",
"data": "\u07c0",
"valid": true
}
]
},
{
"description": "ECMA 262 \\w matches ascii letters only",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"pattern": "^\\w$"
},
"tests": [
{
"description": "ASCII 'a' matches",
"data": "a",
"valid": true
},
{
"description": "latin-1 e-acute does not match (unlike e.g. Python)",
"data": "é",
"valid": false
}
]
},
{
"description": "ECMA 262 \\W matches everything but ascii letters",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"pattern": "^\\W$"
},
"tests": [
{
"description": "ASCII 'a' does not match",
"data": "a",
"valid": false
},
{
"description": "latin-1 e-acute matches (unlike e.g. Python)",
"data": "é",
"valid": true
}
]
},
{
"description": "ECMA 262 \\s matches whitespace",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"pattern": "^\\s$"
},
"tests": [
{
"description": "ASCII space matches",
"data": " ",
"valid": true
},
{
"description": "Character tabulation matches",
"data": "\t",
"valid": true
},
{
"description": "Line tabulation matches",
"data": "\u000b",
"valid": true
},
{
"description": "Form feed matches",
"data": "\u000c",
"valid": true
},
{
"description": "latin-1 non-breaking-space matches",
"data": "\u00a0",
"valid": true
},
{
"description": "zero-width whitespace matches",
"data": "\ufeff",
"valid": true
},
{
"description": "line feed matches (line terminator)",
"data": "\u000a",
"valid": true
},
{
"description": "paragraph separator matches (line terminator)",
"data": "\u2029",
"valid": true
},
{
"description": "EM SPACE matches (Space_Separator)",
"data": "\u2003",
"valid": true
},
{
"description": "Non-whitespace control does not match",
"data": "\u0001",
"valid": false
},
{
"description": "Non-whitespace does not match",
"data": "\u2013",
"valid": false
}
]
},
{
"description": "ECMA 262 \\S matches everything but whitespace",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"pattern": "^\\S$"
},
"tests": [
{
"description": "ASCII space does not match",
"data": " ",
"valid": false
},
{
"description": "Character tabulation does not match",
"data": "\t",
"valid": false
},
{
"description": "Line tabulation does not match",
"data": "\u000b",
"valid": false
},
{
"description": "Form feed does not match",
"data": "\u000c",
"valid": false
},
{
"description": "latin-1 non-breaking-space does not match",
"data": "\u00a0",
"valid": false
},
{
"description": "zero-width whitespace does not match",
"data": "\ufeff",
"valid": false
},
{
"description": "line feed does not match (line terminator)",
"data": "\u000a",
"valid": false
},
{
"description": "paragraph separator does not match (line terminator)",
"data": "\u2029",
"valid": false
},
{
"description": "EM SPACE does not match (Space_Separator)",
"data": "\u2003",
"valid": false
},
{
"description": "Non-whitespace control matches",
"data": "\u0001",
"valid": true
},
{
"description": "Non-whitespace matches",
"data": "\u2013",
"valid": true
}
]
},
{
"description": "patterns always use unicode semantics with pattern",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"pattern": "\\p{Letter}cole"
},
"tests": [
{
"description": "ascii character in json string",
"data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.",
"valid": true
},
{
"description": "literal unicode character in json string",
"data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.",
"valid": true
},
{
"description": "unicode character in hex format in string",
"data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'église et la patinoire; mais la vraie vie était sur la patinoire.",
"valid": true
},
{
"description": "unicode matching is case-sensitive",
"data": "LES HIVERS DE MON ENFANCE ÉTAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ÉCOLE, L'ÉGLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ÉTAIT SUR LA PATINOIRE.",
"valid": false
}
]
},
{
"description": "\\w in patterns matches [A-Za-z0-9_], not unicode letters",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"pattern": "\\wcole"
},
"tests": [
{
"description": "ascii character in json string",
"data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.",
"valid": true
},
{
"description": "literal unicode character in json string",
"data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.",
"valid": false
},
{
"description": "unicode character in hex format in string",
"data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'église et la patinoire; mais la vraie vie était sur la patinoire.",
"valid": false
},
{
"description": "unicode matching is case-sensitive",
"data": "LES HIVERS DE MON ENFANCE ÉTAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ÉCOLE, L'ÉGLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ÉTAIT SUR LA PATINOIRE.",
"valid": false
}
]
},
{
"description": "pattern with ASCII ranges",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"pattern": "[a-z]cole"
},
"tests": [
{
"description": "literal unicode character in json string",
"data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.",
"valid": false
},
{
"description": "unicode character in hex format in string",
"data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'église et la patinoire; mais la vraie vie était sur la patinoire.",
"valid": false
},
{
"description": "ascii characters match",
"data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.",
"valid": true
}
]
},
{
"description": "\\d in pattern matches [0-9], not unicode digits",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"pattern": "^\\d+$"
},
"tests": [
{
"description": "ascii digits",
"data": "42",
"valid": true
},
{
"description": "ascii non-digits",
"data": "-%#",
"valid": false
},
{
"description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)",
"data": "৪২",
"valid": false
}
]
},
{
"description": "pattern with non-ASCII digits",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"pattern": "^\\p{digit}+$"
},
"tests": [
{
"description": "ascii digits",
"data": "42",
"valid": true
},
{
"description": "ascii non-digits",
"data": "-%#",
"valid": false
},
{
"description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)",
"data": "৪২",
"valid": true
}
]
},
{
"description": "patterns always use unicode semantics with patternProperties",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"patternProperties": {
"\\p{Letter}cole": true
},
"additionalProperties": false
},
"tests": [
{
"description": "ascii character in json string",
"data": { "l'ecole": "pas de vraie vie" },
"valid": true
},
{
"description": "literal unicode character in json string",
"data": { "l'école": "pas de vraie vie" },
"valid": true
},
{
"description": "unicode character in hex format in string",
"data": { "l'\u00e9cole": "pas de vraie vie" },
"valid": true
},
{
"description": "unicode matching is case-sensitive",
"data": { "L'ÉCOLE": "PAS DE VRAIE VIE" },
"valid": false
}
]
},
{
"description": "\\w in patternProperties matches [A-Za-z0-9_], not unicode letters",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"patternProperties": {
"\\wcole": true
},
"additionalProperties": false
},
"tests": [
{
"description": "ascii character in json string",
"data": { "l'ecole": "pas de vraie vie" },
"valid": true
},
{
"description": "literal unicode character in json string",
"data": { "l'école": "pas de vraie vie" },
"valid": false
},
{
"description": "unicode character in hex format in string",
"data": { "l'\u00e9cole": "pas de vraie vie" },
"valid": false
},
{
"description": "unicode matching is case-sensitive",
"data": { "L'ÉCOLE": "PAS DE VRAIE VIE" },
"valid": false
}
]
},
{
"description": "patternProperties with ASCII ranges",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"patternProperties": {
"[a-z]cole": true
},
"additionalProperties": false
},
"tests": [
{
"description": "literal unicode character in json string",
"data": { "l'école": "pas de vraie vie" },
"valid": false
},
{
"description": "unicode character in hex format in string",
"data": { "l'\u00e9cole": "pas de vraie vie" },
"valid": false
},
{
"description": "ascii characters match",
"data": { "l'ecole": "pas de vraie vie" },
"valid": true
}
]
},
{
"description": "\\d in patternProperties matches [0-9], not unicode digits",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"patternProperties": {
"^\\d+$": true
},
"additionalProperties": false
},
"tests": [
{
"description": "ascii digits",
"data": { "42": "life, the universe, and everything" },
"valid": true
},
{
"description": "ascii non-digits",
"data": { "-%#": "spending the year dead for tax reasons" },
"valid": false
},
{
"description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)",
"data": { "৪২": "khajit has wares if you have coin" },
"valid": false
}
]
},
{
"description": "patternProperties with non-ASCII digits",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"patternProperties": {
"^\\p{digit}+$": true
},
"additionalProperties": false
},
"tests": [
{
"description": "ascii digits",
"data": { "42": "life, the universe, and everything" },
"valid": true
},
{
"description": "ascii non-digits",
"data": { "-%#": "spending the year dead for tax reasons" },
"valid": false
},
{
"description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)",
"data": { "৪২": "khajit has wares if you have coin" },
"valid": true
}
]
}
]
@@ -0,0 +1,17 @@
[
{
"description": "all integers are multiples of 0.5, if overflow is handled",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "integer",
"multipleOf": 0.5
},
"tests": [
{
"description": "valid if optional overflow handling is implemented",
"data": 1e308,
"valid": true
}
]
}
]
@@ -0,0 +1,42 @@
[
{
"description": "schema that uses custom metaschema with format-assertion: false",
"schema": {
"$id": "https://schema/using/format-assertion/false",
"$schema": "http://localhost:1234/draft2020-12/format-assertion-false.json",
"format": "ipv4"
},
"tests": [
{
"description": "format-assertion: false: valid string",
"data": "127.0.0.1",
"valid": true
},
{
"description": "format-assertion: false: invalid string",
"data": "not-an-ipv4",
"valid": false
}
]
},
{
"description": "schema that uses custom metaschema with format-assertion: true",
"schema": {
"$id": "https://schema/using/format-assertion/true",
"$schema": "http://localhost:1234/draft2020-12/format-assertion-true.json",
"format": "ipv4"
},
"tests": [
{
"description": "format-assertion: true: valid string",
"data": "127.0.0.1",
"valid": true
},
{
"description": "format-assertion: true: invalid string",
"data": "not-an-ipv4",
"valid": false
}
]
}
]
@@ -0,0 +1,141 @@
[
{
"description": "validation of date-time strings",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "date-time"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid date-time string",
"data": "1963-06-19T08:30:06.283185Z",
"valid": true
},
{
"description": "a valid date-time string without second fraction",
"data": "1963-06-19T08:30:06Z",
"valid": true
},
{
"description": "a valid date-time string with plus offset",
"data": "1937-01-01T12:00:27.87+00:20",
"valid": true
},
{
"description": "a valid date-time string with minus offset",
"data": "1990-12-31T15:59:50.123-08:00",
"valid": true
},
{
"description": "a valid date-time with a leap second, UTC",
"data": "1998-12-31T23:59:60Z",
"valid": true
},
{
"description": "a valid date-time with a leap second, with minus offset",
"data": "1998-12-31T15:59:60.123-08:00",
"valid": true
},
{
"description": "an invalid date-time past leap second, UTC",
"data": "1998-12-31T23:59:61Z",
"valid": false
},
{
"description": "an invalid date-time with leap second on a wrong minute, UTC",
"data": "1998-12-31T23:58:60Z",
"valid": false
},
{
"description": "an invalid date-time with leap second on a wrong hour, UTC",
"data": "1998-12-31T22:59:60Z",
"valid": false
},
{
"description": "an invalid day in date-time string",
"data": "1990-02-31T15:59:59.123-08:00",
"valid": false
},
{
"description": "an invalid offset in date-time string",
"data": "1990-12-31T15:59:59-24:00",
"valid": false
},
{
"description": "an invalid closing Z after time-zone offset",
"data": "1963-06-19T08:30:06.28123+01:00Z",
"valid": false
},
{
"description": "an invalid date-time string",
"data": "06/19/1963 08:30:06 PST",
"valid": false
},
{
"description": "case-insensitive T and Z",
"data": "1963-06-19t08:30:06.283185z",
"valid": true
},
{
"description": "only RFC3339 not all of ISO 8601 are valid",
"data": "2013-350T01:01:01",
"valid": false
},
{
"description": "invalid non-padded month dates",
"data": "1963-6-19T08:30:06.283185Z",
"valid": false
},
{
"description": "invalid non-padded day dates",
"data": "1963-06-1T08:30:06.283185Z",
"valid": false
},
{
"description": "invalid non-ASCII '৪' (a Bengali 4) in date portion",
"data": "1963-06-1৪T00:00:00Z",
"valid": false
},
{
"description": "invalid non-ASCII '৪' (a Bengali 4) in time portion",
"data": "1963-06-11T0৪:00:00Z",
"valid": false
},
{
"description": "invalid extended year",
"data": "+11963-06-19T08:30:06.283185Z",
"valid": false
}
]
}
]
@@ -0,0 +1,251 @@
[
{
"description": "validation of date strings",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "date"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid date string",
"data": "1963-06-19",
"valid": true
},
{
"description": "a valid date string with 31 days in January",
"data": "2020-01-31",
"valid": true
},
{
"description": "a invalid date string with 32 days in January",
"data": "2020-01-32",
"valid": false
},
{
"description": "a valid date string with 28 days in February (normal)",
"data": "2021-02-28",
"valid": true
},
{
"description": "a invalid date string with 29 days in February (normal)",
"data": "2021-02-29",
"valid": false
},
{
"description": "a valid date string with 29 days in February (leap)",
"data": "2020-02-29",
"valid": true
},
{
"description": "a invalid date string with 30 days in February (leap)",
"data": "2020-02-30",
"valid": false
},
{
"description": "a valid date string with 31 days in March",
"data": "2020-03-31",
"valid": true
},
{
"description": "a invalid date string with 32 days in March",
"data": "2020-03-32",
"valid": false
},
{
"description": "a valid date string with 30 days in April",
"data": "2020-04-30",
"valid": true
},
{
"description": "a invalid date string with 31 days in April",
"data": "2020-04-31",
"valid": false
},
{
"description": "a valid date string with 31 days in May",
"data": "2020-05-31",
"valid": true
},
{
"description": "a invalid date string with 32 days in May",
"data": "2020-05-32",
"valid": false
},
{
"description": "a valid date string with 30 days in June",
"data": "2020-06-30",
"valid": true
},
{
"description": "a invalid date string with 31 days in June",
"data": "2020-06-31",
"valid": false
},
{
"description": "a valid date string with 31 days in July",
"data": "2020-07-31",
"valid": true
},
{
"description": "a invalid date string with 32 days in July",
"data": "2020-07-32",
"valid": false
},
{
"description": "a valid date string with 31 days in August",
"data": "2020-08-31",
"valid": true
},
{
"description": "a invalid date string with 32 days in August",
"data": "2020-08-32",
"valid": false
},
{
"description": "a valid date string with 30 days in September",
"data": "2020-09-30",
"valid": true
},
{
"description": "a invalid date string with 31 days in September",
"data": "2020-09-31",
"valid": false
},
{
"description": "a valid date string with 31 days in October",
"data": "2020-10-31",
"valid": true
},
{
"description": "a invalid date string with 32 days in October",
"data": "2020-10-32",
"valid": false
},
{
"description": "a valid date string with 30 days in November",
"data": "2020-11-30",
"valid": true
},
{
"description": "a invalid date string with 31 days in November",
"data": "2020-11-31",
"valid": false
},
{
"description": "a valid date string with 31 days in December",
"data": "2020-12-31",
"valid": true
},
{
"description": "a invalid date string with 32 days in December",
"data": "2020-12-32",
"valid": false
},
{
"description": "a invalid date string with invalid month",
"data": "2020-13-01",
"valid": false
},
{
"description": "an invalid date string",
"data": "06/19/1963",
"valid": false
},
{
"description": "only RFC3339 not all of ISO 8601 are valid",
"data": "2013-350",
"valid": false
},
{
"description": "non-padded month dates are not valid",
"data": "1998-1-20",
"valid": false
},
{
"description": "non-padded day dates are not valid",
"data": "1998-01-1",
"valid": false
},
{
"description": "invalid month",
"data": "1998-13-01",
"valid": false
},
{
"description": "invalid month-day combination",
"data": "1998-04-31",
"valid": false
},
{
"description": "2021 is not a leap year",
"data": "2021-02-29",
"valid": false
},
{
"description": "2020 is a leap year",
"data": "2020-02-29",
"valid": true
},
{
"description": "invalid non-ASCII '৪' (a Bengali 4)",
"data": "1963-06-1৪",
"valid": false
},
{
"description": "ISO8601 / non-RFC3339: YYYYMMDD without dashes (2023-03-28)",
"data": "20230328",
"valid": false
},
{
"description": "ISO8601 / non-RFC3339: week number implicit day of week (2023-01-02)",
"data": "2023-W01",
"valid": false
},
{
"description": "ISO8601 / non-RFC3339: week number with day of week (2023-03-28)",
"data": "2023-W13-2",
"valid": false
},
{
"description": "ISO8601 / non-RFC3339: week number rollover to next year (2023-01-01)",
"data": "2022W527",
"valid": false
},
{
"description": "an invalid time string in date-time format",
"data": "2020-11-28T23:55:45Z",
"valid": false
}
]
}
]
@@ -0,0 +1,141 @@
[
{
"description": "validation of duration strings",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "duration"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid duration string",
"data": "P4DT12H30M5S",
"valid": true
},
{
"description": "an invalid duration string",
"data": "PT1D",
"valid": false
},
{
"description": "must start with P",
"data": "4DT12H30M5S",
"valid": false
},
{
"description": "no elements present",
"data": "P",
"valid": false
},
{
"description": "no time elements present",
"data": "P1YT",
"valid": false
},
{
"description": "no date or time elements present",
"data": "PT",
"valid": false
},
{
"description": "elements out of order",
"data": "P2D1Y",
"valid": false
},
{
"description": "missing time separator",
"data": "P1D2H",
"valid": false
},
{
"description": "time element in the date position",
"data": "P2S",
"valid": false
},
{
"description": "four years duration",
"data": "P4Y",
"valid": true
},
{
"description": "zero time, in seconds",
"data": "PT0S",
"valid": true
},
{
"description": "zero time, in days",
"data": "P0D",
"valid": true
},
{
"description": "one month duration",
"data": "P1M",
"valid": true
},
{
"description": "one minute duration",
"data": "PT1M",
"valid": true
},
{
"description": "one and a half days, in hours",
"data": "PT36H",
"valid": true
},
{
"description": "one and a half days, in days and hours",
"data": "P1DT12H",
"valid": true
},
{
"description": "two weeks",
"data": "P2W",
"valid": true
},
{
"description": "weeks cannot be combined with other units",
"data": "P1Y2W",
"valid": false
},
{
"description": "invalid non-ASCII '২' (a Bengali 2)",
"data": "P২Y",
"valid": false
},
{
"description": "element without unit",
"data": "P1",
"valid": false
}
]
}
]
@@ -0,0 +1,16 @@
[
{
"description": "\\a is not an ECMA 262 control escape",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "regex"
},
"tests": [
{
"description": "when used as a pattern",
"data": "\\a",
"valid": false
}
]
}
]
@@ -0,0 +1,131 @@
[
{
"description": "validation of e-mail addresses",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "email"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid e-mail address",
"data": "joe.bloggs@example.com",
"valid": true
},
{
"description": "an invalid e-mail address",
"data": "2962",
"valid": false
},
{
"description": "tilde in local part is valid",
"data": "te~st@example.com",
"valid": true
},
{
"description": "tilde before local part is valid",
"data": "~test@example.com",
"valid": true
},
{
"description": "tilde after local part is valid",
"data": "test~@example.com",
"valid": true
},
{
"description": "a quoted string with a space in the local part is valid",
"data": "\"joe bloggs\"@example.com",
"valid": true
},
{
"description": "a quoted string with a double dot in the local part is valid",
"data": "\"joe..bloggs\"@example.com",
"valid": true
},
{
"description": "a quoted string with a @ in the local part is valid",
"data": "\"joe@bloggs\"@example.com",
"valid": true
},
{
"description": "an IPv4-address-literal after the @ is valid",
"data": "joe.bloggs@[127.0.0.1]",
"valid": true
},
{
"description": "an IPv6-address-literal after the @ is valid",
"data": "joe.bloggs@[IPv6:::1]",
"valid": true
},
{
"description": "dot before local part is not valid",
"data": ".test@example.com",
"valid": false
},
{
"description": "dot after local part is not valid",
"data": "test.@example.com",
"valid": false
},
{
"description": "two separated dots inside local part are valid",
"data": "te.s.t@example.com",
"valid": true
},
{
"description": "two subsequent dots inside local part are not valid",
"data": "te..st@example.com",
"valid": false
},
{
"description": "an invalid domain",
"data": "joe.bloggs@invalid=domain.com",
"valid": false
},
{
"description": "an invalid IPv4-address-literal",
"data": "joe.bloggs@[127.0.0.300]",
"valid": false
},
{
"description": "two email addresses is not valid",
"data": "user1@oceania.org, user2@oceania.org",
"valid": false
},
{
"description": "full \"From\" header is invalid",
"data": "\"Winston Smith\" <winston.smith@recdep.minitrue> (Records Department)",
"valid": false
}
]
}
]
@@ -0,0 +1,361 @@
[
{
"description": "validation of host names",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "hostname"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid host name",
"data": "www.example.com",
"valid": true
},
{
"description": "single label",
"data": "hostname",
"valid": true
},
{
"description": "single label with digits",
"data": "h0stn4me",
"valid": true
},
{
"description": "single label starting with digit",
"data": "1host",
"valid": true
},
{
"description": "single label ending with digit",
"data": "hostnam3",
"valid": true
},
{
"description": "empty string",
"data": "",
"valid": false
},
{
"description": "single dot",
"data": ".",
"valid": false
},
{
"description": "leading dot",
"data": ".example",
"valid": false
},
{
"description": "trailing dot",
"data": "example.",
"valid": false
},
{
"description": "IDN label separator",
"data": "example\uff0ecom",
"valid": false
},
{
"description": "single label with hyphen",
"data": "host-name",
"valid": true
},
{
"description": "starts with hyphen",
"data": "-hostname",
"valid": false
},
{
"description": "ends with hyphen",
"data": "hostname-",
"valid": false
},
{
"description": "contains \"--\" in the 3rd and 4th position",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1 https://tools.ietf.org/html/rfc5890#section-2.3.2.1",
"data": "XN--aa---o47jg78q",
"valid": false
},
{
"description": "contains underscore",
"data": "host_name",
"valid": false
},
{
"description": "exceeds maximum overall length (256)",
"data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com",
"valid": false
},
{
"description": "maximum label length (63)",
"data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com",
"valid": true
},
{
"description": "exceeds maximum label length (63)",
"data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com",
"valid": false
}
]
},
{
"description": "validation of A-label (punycode) host names",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "hostname"
},
"tests": [
{
"description": "invalid Punycode",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc5890#section-2.3.2.1",
"data": "xn--X",
"valid": false
},
{
"description": "a valid host name (example.test in Hangul)",
"data": "xn--9n2bp8q.xn--9t4b11yi5a",
"valid": true
},
{
"description": "contains illegal char U+302E Hangul single dot tone mark",
"data": "xn--07jt112bpxg.xn--9t4b11yi5a",
"valid": false
},
{
"description": "Begins with a Spacing Combining Mark",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2",
"data": "xn--hello-txk",
"valid": false
},
{
"description": "Begins with a Nonspacing Mark",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2",
"data": "xn--hello-zed",
"valid": false
},
{
"description": "Begins with an Enclosing Mark",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2",
"data": "xn--hello-6bf",
"valid": false
},
{
"description": "Exceptions that are PVALID, left-to-right chars",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6",
"data": "xn--zca29lwxobi7a",
"valid": true
},
{
"description": "Exceptions that are PVALID, right-to-left chars",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6",
"data": "xn--qmbc",
"valid": true
},
{
"description": "Exceptions that are DISALLOWED, right-to-left chars",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6",
"data": "xn--chb89f",
"valid": false
},
{
"description": "Exceptions that are DISALLOWED, left-to-right chars",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6 Note: The two combining marks (U+302E and U+302F) are in the middle and not at the start",
"data": "xn--07jceefgh4c",
"valid": false
},
{
"description": "MIDDLE DOT with no preceding 'l'",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3",
"data": "xn--al-0ea",
"valid": false
},
{
"description": "MIDDLE DOT with nothing preceding",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3",
"data": "xn--l-fda",
"valid": false
},
{
"description": "MIDDLE DOT with no following 'l'",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3",
"data": "xn--la-0ea",
"valid": false
},
{
"description": "MIDDLE DOT with nothing following",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3",
"data": "xn--l-gda",
"valid": false
},
{
"description": "MIDDLE DOT with surrounding 'l's",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3",
"data": "xn--ll-0ea",
"valid": true
},
{
"description": "Greek KERAIA not followed by Greek",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4",
"data": "xn--S-jib3p",
"valid": false
},
{
"description": "Greek KERAIA not followed by anything",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4",
"data": "xn--wva3j",
"valid": false
},
{
"description": "Greek KERAIA followed by Greek",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4",
"data": "xn--wva3je",
"valid": true
},
{
"description": "Hebrew GERESH not preceded by Hebrew",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5",
"data": "xn--A-2hc5h",
"valid": false
},
{
"description": "Hebrew GERESH not preceded by anything",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5",
"data": "xn--5db1e",
"valid": false
},
{
"description": "Hebrew GERESH preceded by Hebrew",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5",
"data": "xn--4dbc5h",
"valid": true
},
{
"description": "Hebrew GERSHAYIM not preceded by Hebrew",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6",
"data": "xn--A-2hc8h",
"valid": false
},
{
"description": "Hebrew GERSHAYIM not preceded by anything",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6",
"data": "xn--5db3e",
"valid": false
},
{
"description": "Hebrew GERSHAYIM preceded by Hebrew",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6",
"data": "xn--4dbc8h",
"valid": true
},
{
"description": "KATAKANA MIDDLE DOT with no Hiragana, Katakana, or Han",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7",
"data": "xn--defabc-k64e",
"valid": false
},
{
"description": "KATAKANA MIDDLE DOT with no other characters",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7",
"data": "xn--vek",
"valid": false
},
{
"description": "KATAKANA MIDDLE DOT with Hiragana",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7",
"data": "xn--k8j5u",
"valid": true
},
{
"description": "KATAKANA MIDDLE DOT with Katakana",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7",
"data": "xn--bck0j",
"valid": true
},
{
"description": "KATAKANA MIDDLE DOT with Han",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7",
"data": "xn--vek778f",
"valid": true
},
{
"description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8",
"data": "xn--ngb6iyr",
"valid": false
},
{
"description": "Arabic-Indic digits not mixed with Extended Arabic-Indic digits",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8",
"data": "xn--ngba1o",
"valid": true
},
{
"description": "Extended Arabic-Indic digits not mixed with Arabic-Indic digits",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.9",
"data": "xn--0-gyc",
"valid": true
},
{
"description": "ZERO WIDTH JOINER not preceded by Virama",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf",
"data": "xn--11b2er09f",
"valid": false
},
{
"description": "ZERO WIDTH JOINER not preceded by anything",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf",
"data": "xn--02b508i",
"valid": false
},
{
"description": "ZERO WIDTH JOINER preceded by Virama",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf",
"data": "xn--11b2ezcw70k",
"valid": true
},
{
"description": "ZERO WIDTH NON-JOINER preceded by Virama",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1",
"data": "xn--11b2ezcs70k",
"valid": true
},
{
"description": "ZERO WIDTH NON-JOINER not preceded by Virama but matches regexp",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement",
"data": "xn--ngba5hb2804a",
"valid": true
}
]
}
]
@@ -0,0 +1,61 @@
[
{
"description": "validation of an internationalized e-mail addresses",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "idn-email"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid idn e-mail (example@example.test in Hangul)",
"data": "실례@실례.테스트",
"valid": true
},
{
"description": "an invalid idn e-mail address",
"data": "2962",
"valid": false
},
{
"description": "a valid e-mail address",
"data": "joe.bloggs@example.com",
"valid": true
},
{
"description": "an invalid e-mail address",
"data": "2962",
"valid": false
}
]
}
]
@@ -0,0 +1,449 @@
[
{
"description": "validation of internationalized host names",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "idn-hostname"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid host name (example.test in Hangul)",
"data": "실례.테스트",
"valid": true
},
{
"description": "illegal first char U+302E Hangul single dot tone mark",
"data": "〮실례.테스트",
"valid": false
},
{
"description": "contains illegal char U+302E Hangul single dot tone mark",
"data": "실〮례.테스트",
"valid": false
},
{
"description": "a host name with a component too long",
"data": "실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실례례테스트례례례례례례례례례례례례례례례례례테스트례례례례례례례례례례례례례례례례례례례테스트례례례례례례례례례례례례테스트례례실례.테스트",
"valid": false
},
{
"description": "invalid label, correct Punycode",
"comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc3492#section-7.1",
"data": "-> $1.00 <--",
"valid": false
},
{
"description": "valid Chinese Punycode",
"comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4",
"data": "xn--ihqwcrb4cv8a8dqg056pqjye",
"valid": true
},
{
"description": "invalid Punycode",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc5890#section-2.3.2.1",
"data": "xn--X",
"valid": false
},
{
"description": "U-label contains \"--\" in the 3rd and 4th position",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1 https://tools.ietf.org/html/rfc5890#section-2.3.2.1",
"data": "XN--aa---o47jg78q",
"valid": false
},
{
"description": "U-label starts with a dash",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1",
"data": "-hello",
"valid": false
},
{
"description": "U-label ends with a dash",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1",
"data": "hello-",
"valid": false
},
{
"description": "U-label starts and ends with a dash",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1",
"data": "-hello-",
"valid": false
},
{
"description": "Begins with a Spacing Combining Mark",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2",
"data": "\u0903hello",
"valid": false
},
{
"description": "Begins with a Nonspacing Mark",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2",
"data": "\u0300hello",
"valid": false
},
{
"description": "Begins with an Enclosing Mark",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2",
"data": "\u0488hello",
"valid": false
},
{
"description": "Exceptions that are PVALID, left-to-right chars",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6",
"data": "\u00df\u03c2\u0f0b\u3007",
"valid": true
},
{
"description": "Exceptions that are PVALID, right-to-left chars",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6",
"data": "\u06fd\u06fe",
"valid": true
},
{
"description": "Exceptions that are DISALLOWED, right-to-left chars",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6",
"data": "\u0640\u07fa",
"valid": false
},
{
"description": "Exceptions that are DISALLOWED, left-to-right chars",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6 Note: The two combining marks (U+302E and U+302F) are in the middle and not at the start",
"data": "\u3031\u3032\u3033\u3034\u3035\u302e\u302f\u303b",
"valid": false
},
{
"description": "MIDDLE DOT with no preceding 'l'",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3",
"data": "a\u00b7l",
"valid": false
},
{
"description": "MIDDLE DOT with nothing preceding",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3",
"data": "\u00b7l",
"valid": false
},
{
"description": "MIDDLE DOT with no following 'l'",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3",
"data": "l\u00b7a",
"valid": false
},
{
"description": "MIDDLE DOT with nothing following",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3",
"data": "l\u00b7",
"valid": false
},
{
"description": "MIDDLE DOT with surrounding 'l's",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3",
"data": "l\u00b7l",
"valid": true
},
{
"description": "Greek KERAIA not followed by Greek",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4",
"data": "\u03b1\u0375S",
"valid": false
},
{
"description": "Greek KERAIA not followed by anything",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4",
"data": "\u03b1\u0375",
"valid": false
},
{
"description": "Greek KERAIA followed by Greek",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4",
"data": "\u03b1\u0375\u03b2",
"valid": true
},
{
"description": "Hebrew GERESH not preceded by Hebrew",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5",
"data": "A\u05f3\u05d1",
"valid": false
},
{
"description": "Hebrew GERESH not preceded by anything",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5",
"data": "\u05f3\u05d1",
"valid": false
},
{
"description": "Hebrew GERESH preceded by Hebrew",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5",
"data": "\u05d0\u05f3\u05d1",
"valid": true
},
{
"description": "Hebrew GERSHAYIM not preceded by Hebrew",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6",
"data": "A\u05f4\u05d1",
"valid": false
},
{
"description": "Hebrew GERSHAYIM not preceded by anything",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6",
"data": "\u05f4\u05d1",
"valid": false
},
{
"description": "Hebrew GERSHAYIM preceded by Hebrew",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6",
"data": "\u05d0\u05f4\u05d1",
"valid": true
},
{
"description": "KATAKANA MIDDLE DOT with no Hiragana, Katakana, or Han",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7",
"data": "def\u30fbabc",
"valid": false
},
{
"description": "KATAKANA MIDDLE DOT with no other characters",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7",
"data": "\u30fb",
"valid": false
},
{
"description": "KATAKANA MIDDLE DOT with Hiragana",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7",
"data": "\u30fb\u3041",
"valid": true
},
{
"description": "KATAKANA MIDDLE DOT with Katakana",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7",
"data": "\u30fb\u30a1",
"valid": true
},
{
"description": "KATAKANA MIDDLE DOT with Han",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7",
"data": "\u30fb\u4e08",
"valid": true
},
{
"description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8",
"data": "\u0628\u0660\u06f0",
"valid": false
},
{
"description": "Arabic-Indic digits not mixed with Extended Arabic-Indic digits",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8",
"data": "\u0628\u0660\u0628",
"valid": true
},
{
"description": "Extended Arabic-Indic digits not mixed with Arabic-Indic digits",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.9",
"data": "\u06f00",
"valid": true
},
{
"description": "ZERO WIDTH JOINER not preceded by Virama",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf",
"data": "\u0915\u200d\u0937",
"valid": false
},
{
"description": "ZERO WIDTH JOINER not preceded by anything",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf",
"data": "\u200d\u0937",
"valid": false
},
{
"description": "ZERO WIDTH JOINER preceded by Virama",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf",
"data": "\u0915\u094d\u200d\u0937",
"valid": true
},
{
"description": "ZERO WIDTH NON-JOINER preceded by Virama",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1",
"data": "\u0915\u094d\u200c\u0937",
"valid": true
},
{
"description": "ZERO WIDTH NON-JOINER not preceded by Virama but matches regexp",
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement",
"data": "\u0628\u064a\u200c\u0628\u064a",
"valid": true
},
{
"description": "single label",
"data": "hostname",
"valid": true
},
{
"description": "single label with hyphen",
"data": "host-name",
"valid": true
},
{
"description": "single label with digits",
"data": "h0stn4me",
"valid": true
},
{
"description": "single label starting with digit",
"data": "1host",
"valid": true
},
{
"description": "single label ending with digit",
"data": "hostnam3",
"valid": true
},
{
"description": "empty string",
"data": "",
"valid": false
}
]
},
{
"description": "validation of separators in internationalized host names",
"specification": [
{"rfc3490": "3.1", "quote": "Whenever dots are used as label separators, the following characters MUST be recognized as dots: U+002E (full stop), U+3002 (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61(halfwidth ideographic full stop)"}
],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "idn-hostname"
},
"tests": [
{
"description": "single dot",
"data": ".",
"valid": false
},
{
"description": "single ideographic full stop",
"data": "\u3002",
"valid": false
},
{
"description": "single fullwidth full stop",
"data": "\uff0e",
"valid": false
},
{
"description": "single halfwidth ideographic full stop",
"data": "\uff61",
"valid": false
},
{
"description": "dot as label separator",
"data": "a.b",
"valid": true
},
{
"description": "ideographic full stop as label separator",
"data": "a\u3002b",
"valid": true
},
{
"description": "fullwidth full stop as label separator",
"data": "a\uff0eb",
"valid": true
},
{
"description": "halfwidth ideographic full stop as label separator",
"data": "a\uff61b",
"valid": true
},
{
"description": "leading dot",
"data": ".example",
"valid": false
},
{
"description": "leading ideographic full stop",
"data": "\u3002example",
"valid": false
},
{
"description": "leading fullwidth full stop",
"data": "\uff0eexample",
"valid": false
},
{
"description": "leading halfwidth ideographic full stop",
"data": "\uff61example",
"valid": false
},
{
"description": "trailing dot",
"data": "example.",
"valid": false
},
{
"description": "trailing ideographic full stop",
"data": "example\u3002",
"valid": false
},
{
"description": "trailing fullwidth full stop",
"data": "example\uff0e",
"valid": false
},
{
"description": "trailing halfwidth ideographic full stop",
"data": "example\uff61",
"valid": false
},
{
"description": "label too long if separator ignored (full stop)",
"data": "παράδειγμαπαράδειγμαπαράδειγμαπαράδειγμαπαράδειγμαπα.com",
"valid": true
},
{
"description": "label too long if separator ignored (ideographic full stop)",
"data": "παράδειγμαπαράδειγμαπαράδειγμαπαράδειγμαπαράδειγμαπα\u3002com",
"valid": true
},
{
"description": "label too long if separator ignored (fullwidth full stop)",
"data": "παράδειγμαπαράδειγμαπαράδειγμαπαράδειγμαπαράδειγμαπα\uff0ecom",
"valid": true
},
{
"description": "label too long if separator ignored (halfwidth ideographic full stop)",
"data": "παράδειγμαπαράδειγμαπαράδειγμαπαράδειγμαπαράδειγμαπα\uff61com",
"valid": true
}
]
}
]
@@ -0,0 +1,92 @@
[
{
"description": "validation of IP addresses",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "ipv4"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid IP address",
"data": "192.168.0.1",
"valid": true
},
{
"description": "an IP address with too many components",
"data": "127.0.0.0.1",
"valid": false
},
{
"description": "an IP address with out-of-range values",
"data": "256.256.256.256",
"valid": false
},
{
"description": "an IP address without 4 components",
"data": "127.0",
"valid": false
},
{
"description": "an IP address as an integer",
"data": "0x7f000001",
"valid": false
},
{
"description": "an IP address as an integer (decimal)",
"data": "2130706433",
"valid": false
},
{
"description": "invalid leading zeroes, as they are treated as octals",
"comment": "see https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/",
"data": "087.10.0.1",
"valid": false
},
{
"description": "value without leading zero is valid",
"data": "87.10.0.1",
"valid": true
},
{
"description": "invalid non-ASCII '২' (a Bengali 2)",
"data": "1২7.0.0.1",
"valid": false
},
{
"description": "netmask is not a part of ipv4 address",
"data": "192.168.1.0/24",
"valid": false
}
]
}
]
@@ -0,0 +1,211 @@
[
{
"description": "validation of IPv6 addresses",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "ipv6"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid IPv6 address",
"data": "::1",
"valid": true
},
{
"description": "an IPv6 address with out-of-range values",
"data": "12345::",
"valid": false
},
{
"description": "trailing 4 hex symbols is valid",
"data": "::abef",
"valid": true
},
{
"description": "trailing 5 hex symbols is invalid",
"data": "::abcef",
"valid": false
},
{
"description": "an IPv6 address with too many components",
"data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1",
"valid": false
},
{
"description": "an IPv6 address containing illegal characters",
"data": "::laptop",
"valid": false
},
{
"description": "no digits is valid",
"data": "::",
"valid": true
},
{
"description": "leading colons is valid",
"data": "::42:ff:1",
"valid": true
},
{
"description": "trailing colons is valid",
"data": "d6::",
"valid": true
},
{
"description": "missing leading octet is invalid",
"data": ":2:3:4:5:6:7:8",
"valid": false
},
{
"description": "missing trailing octet is invalid",
"data": "1:2:3:4:5:6:7:",
"valid": false
},
{
"description": "missing leading octet with omitted octets later",
"data": ":2:3:4::8",
"valid": false
},
{
"description": "single set of double colons in the middle is valid",
"data": "1:d6::42",
"valid": true
},
{
"description": "two sets of double colons is invalid",
"data": "1::d6::42",
"valid": false
},
{
"description": "mixed format with the ipv4 section as decimal octets",
"data": "1::d6:192.168.0.1",
"valid": true
},
{
"description": "mixed format with double colons between the sections",
"data": "1:2::192.168.0.1",
"valid": true
},
{
"description": "mixed format with ipv4 section with octet out of range",
"data": "1::2:192.168.256.1",
"valid": false
},
{
"description": "mixed format with ipv4 section with a hex octet",
"data": "1::2:192.168.ff.1",
"valid": false
},
{
"description": "mixed format with leading double colons (ipv4-mapped ipv6 address)",
"data": "::ffff:192.168.0.1",
"valid": true
},
{
"description": "triple colons is invalid",
"data": "1:2:3:4:5:::8",
"valid": false
},
{
"description": "8 octets",
"data": "1:2:3:4:5:6:7:8",
"valid": true
},
{
"description": "insufficient octets without double colons",
"data": "1:2:3:4:5:6:7",
"valid": false
},
{
"description": "no colons is invalid",
"data": "1",
"valid": false
},
{
"description": "ipv4 is not ipv6",
"data": "127.0.0.1",
"valid": false
},
{
"description": "ipv4 segment must have 4 octets",
"data": "1:2:3:4:1.2.3",
"valid": false
},
{
"description": "leading whitespace is invalid",
"data": " ::1",
"valid": false
},
{
"description": "trailing whitespace is invalid",
"data": "::1 ",
"valid": false
},
{
"description": "netmask is not a part of ipv6 address",
"data": "fe80::/64",
"valid": false
},
{
"description": "zone id is not a part of ipv6 address",
"data": "fe80::a%eth1",
"valid": false
},
{
"description": "a long valid ipv6",
"data": "1000:1000:1000:1000:1000:1000:255.255.255.255",
"valid": true
},
{
"description": "a long invalid ipv6, below length limit, first",
"data": "100:100:100:100:100:100:255.255.255.255.255",
"valid": false
},
{
"description": "a long invalid ipv6, below length limit, second",
"data": "100:100:100:100:100:100:100:255.255.255.255",
"valid": false
},
{
"description": "invalid non-ASCII '৪' (a Bengali 4)",
"data": "1:2:3:4:5:6:7:৪",
"valid": false
},
{
"description": "invalid non-ASCII '৪' (a Bengali 4) in the IPv4 portion",
"data": "1:2::192.16৪.0.1",
"valid": false
}
]
}
]
@@ -0,0 +1,76 @@
[
{
"description": "validation of IRI References",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "iri-reference"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid IRI",
"data": "http://ƒøø.ßår/?∂éœ=πîx#πîüx",
"valid": true
},
{
"description": "a valid protocol-relative IRI Reference",
"data": "//ƒøø.ßår/?∂éœ=πîx#πîüx",
"valid": true
},
{
"description": "a valid relative IRI Reference",
"data": "/âππ",
"valid": true
},
{
"description": "an invalid IRI Reference",
"data": "\\\\WINDOWS\\filëßåré",
"valid": false
},
{
"description": "a valid IRI Reference",
"data": "âππ",
"valid": true
},
{
"description": "a valid IRI fragment",
"data": "#ƒrägmênt",
"valid": true
},
{
"description": "an invalid IRI fragment",
"data": "#ƒräg\\mênt",
"valid": false
}
]
}
]
@@ -0,0 +1,86 @@
[
{
"description": "validation of IRIs",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "iri"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid IRI with anchor tag",
"data": "http://ƒøø.ßår/?∂éœ=πîx#πîüx",
"valid": true
},
{
"description": "a valid IRI with anchor tag and parentheses",
"data": "http://ƒøø.com/blah_(wîkïpédiå)_blah#ßité-1",
"valid": true
},
{
"description": "a valid IRI with URL-encoded stuff",
"data": "http://ƒøø.ßår/?q=Test%20URL-encoded%20stuff",
"valid": true
},
{
"description": "a valid IRI with many special characters",
"data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com",
"valid": true
},
{
"description": "a valid IRI based on IPv6",
"data": "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]",
"valid": true
},
{
"description": "an invalid IRI based on IPv6",
"data": "http://2001:0db8:85a3:0000:0000:8a2e:0370:7334",
"valid": false
},
{
"description": "an invalid relative IRI Reference",
"data": "/abc",
"valid": false
},
{
"description": "an invalid IRI",
"data": "\\\\WINDOWS\\filëßåré",
"valid": false
},
{
"description": "an invalid IRI though valid IRI reference",
"data": "âππ",
"valid": false
}
]
}
]
@@ -0,0 +1,201 @@
[
{
"description": "validation of JSON-pointers (JSON String Representation)",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "json-pointer"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid JSON-pointer",
"data": "/foo/bar~0/baz~1/%a",
"valid": true
},
{
"description": "not a valid JSON-pointer (~ not escaped)",
"data": "/foo/bar~",
"valid": false
},
{
"description": "valid JSON-pointer with empty segment",
"data": "/foo//bar",
"valid": true
},
{
"description": "valid JSON-pointer with the last empty segment",
"data": "/foo/bar/",
"valid": true
},
{
"description": "valid JSON-pointer as stated in RFC 6901 #1",
"data": "",
"valid": true
},
{
"description": "valid JSON-pointer as stated in RFC 6901 #2",
"data": "/foo",
"valid": true
},
{
"description": "valid JSON-pointer as stated in RFC 6901 #3",
"data": "/foo/0",
"valid": true
},
{
"description": "valid JSON-pointer as stated in RFC 6901 #4",
"data": "/",
"valid": true
},
{
"description": "valid JSON-pointer as stated in RFC 6901 #5",
"data": "/a~1b",
"valid": true
},
{
"description": "valid JSON-pointer as stated in RFC 6901 #6",
"data": "/c%d",
"valid": true
},
{
"description": "valid JSON-pointer as stated in RFC 6901 #7",
"data": "/e^f",
"valid": true
},
{
"description": "valid JSON-pointer as stated in RFC 6901 #8",
"data": "/g|h",
"valid": true
},
{
"description": "valid JSON-pointer as stated in RFC 6901 #9",
"data": "/i\\j",
"valid": true
},
{
"description": "valid JSON-pointer as stated in RFC 6901 #10",
"data": "/k\"l",
"valid": true
},
{
"description": "valid JSON-pointer as stated in RFC 6901 #11",
"data": "/ ",
"valid": true
},
{
"description": "valid JSON-pointer as stated in RFC 6901 #12",
"data": "/m~0n",
"valid": true
},
{
"description": "valid JSON-pointer used adding to the last array position",
"data": "/foo/-",
"valid": true
},
{
"description": "valid JSON-pointer (- used as object member name)",
"data": "/foo/-/bar",
"valid": true
},
{
"description": "valid JSON-pointer (multiple escaped characters)",
"data": "/~1~0~0~1~1",
"valid": true
},
{
"description": "valid JSON-pointer (escaped with fraction part) #1",
"data": "/~1.1",
"valid": true
},
{
"description": "valid JSON-pointer (escaped with fraction part) #2",
"data": "/~0.1",
"valid": true
},
{
"description": "not a valid JSON-pointer (URI Fragment Identifier) #1",
"data": "#",
"valid": false
},
{
"description": "not a valid JSON-pointer (URI Fragment Identifier) #2",
"data": "#/",
"valid": false
},
{
"description": "not a valid JSON-pointer (URI Fragment Identifier) #3",
"data": "#a",
"valid": false
},
{
"description": "not a valid JSON-pointer (some escaped, but not all) #1",
"data": "/~0~",
"valid": false
},
{
"description": "not a valid JSON-pointer (some escaped, but not all) #2",
"data": "/~0/~",
"valid": false
},
{
"description": "not a valid JSON-pointer (wrong escape character) #1",
"data": "/~2",
"valid": false
},
{
"description": "not a valid JSON-pointer (wrong escape character) #2",
"data": "/~-1",
"valid": false
},
{
"description": "not a valid JSON-pointer (multiple characters not escaped)",
"data": "/~~",
"valid": false
},
{
"description": "not a valid JSON-pointer (isn't empty nor starts with /) #1",
"data": "a",
"valid": false
},
{
"description": "not a valid JSON-pointer (isn't empty nor starts with /) #2",
"data": "0",
"valid": false
},
{
"description": "not a valid JSON-pointer (isn't empty nor starts with /) #3",
"data": "a/a",
"valid": false
}
]
}
]
@@ -0,0 +1,51 @@
[
{
"description": "validation of regular expressions",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "regex"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid regular expression",
"data": "([abc])+\\s+$",
"valid": true
},
{
"description": "a regular expression with unclosed parens is invalid",
"data": "^(abc]",
"valid": false
}
]
}
]
@@ -0,0 +1,101 @@
[
{
"description": "validation of Relative JSON Pointers (RJP)",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "relative-json-pointer"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid upwards RJP",
"data": "1",
"valid": true
},
{
"description": "a valid downwards RJP",
"data": "0/foo/bar",
"valid": true
},
{
"description": "a valid up and then down RJP, with array index",
"data": "2/0/baz/1/zip",
"valid": true
},
{
"description": "a valid RJP taking the member or index name",
"data": "0#",
"valid": true
},
{
"description": "an invalid RJP that is a valid JSON Pointer",
"data": "/foo/bar",
"valid": false
},
{
"description": "negative prefix",
"data": "-1/foo/bar",
"valid": false
},
{
"description": "explicit positive prefix",
"data": "+1/foo/bar",
"valid": false
},
{
"description": "## is not a valid json-pointer",
"data": "0##",
"valid": false
},
{
"description": "zero cannot be followed by other digits, plus json-pointer",
"data": "01/a",
"valid": false
},
{
"description": "zero cannot be followed by other digits, plus octothorpe",
"data": "01#",
"valid": false
},
{
"description": "empty string",
"data": "",
"valid": false
},
{
"description": "multi-digit integer prefix",
"data": "120/foo/bar",
"valid": true
}
]
}
]
@@ -0,0 +1,241 @@
[
{
"description": "validation of time strings",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "time"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid time string",
"data": "08:30:06Z",
"valid": true
},
{
"description": "invalid time string with extra leading zeros",
"data": "008:030:006Z",
"valid": false
},
{
"description": "invalid time string with no leading zero for single digit",
"data": "8:3:6Z",
"valid": false
},
{
"description": "hour, minute, second must be two digits",
"data": "8:0030:6Z",
"valid": false
},
{
"description": "a valid time string with leap second, Zulu",
"data": "23:59:60Z",
"valid": true
},
{
"description": "invalid leap second, Zulu (wrong hour)",
"data": "22:59:60Z",
"valid": false
},
{
"description": "invalid leap second, Zulu (wrong minute)",
"data": "23:58:60Z",
"valid": false
},
{
"description": "valid leap second, zero time-offset",
"data": "23:59:60+00:00",
"valid": true
},
{
"description": "invalid leap second, zero time-offset (wrong hour)",
"data": "22:59:60+00:00",
"valid": false
},
{
"description": "invalid leap second, zero time-offset (wrong minute)",
"data": "23:58:60+00:00",
"valid": false
},
{
"description": "valid leap second, positive time-offset",
"data": "01:29:60+01:30",
"valid": true
},
{
"description": "valid leap second, large positive time-offset",
"data": "23:29:60+23:30",
"valid": true
},
{
"description": "invalid leap second, positive time-offset (wrong hour)",
"data": "23:59:60+01:00",
"valid": false
},
{
"description": "invalid leap second, positive time-offset (wrong minute)",
"data": "23:59:60+00:30",
"valid": false
},
{
"description": "valid leap second, negative time-offset",
"data": "15:59:60-08:00",
"valid": true
},
{
"description": "valid leap second, large negative time-offset",
"data": "00:29:60-23:30",
"valid": true
},
{
"description": "invalid leap second, negative time-offset (wrong hour)",
"data": "23:59:60-01:00",
"valid": false
},
{
"description": "invalid leap second, negative time-offset (wrong minute)",
"data": "23:59:60-00:30",
"valid": false
},
{
"description": "a valid time string with second fraction",
"data": "23:20:50.52Z",
"valid": true
},
{
"description": "a valid time string with precise second fraction",
"data": "08:30:06.283185Z",
"valid": true
},
{
"description": "a valid time string with plus offset",
"data": "08:30:06+00:20",
"valid": true
},
{
"description": "a valid time string with minus offset",
"data": "08:30:06-08:00",
"valid": true
},
{
"description": "hour, minute in time-offset must be two digits",
"data": "08:30:06-8:000",
"valid": false
},
{
"description": "a valid time string with case-insensitive Z",
"data": "08:30:06z",
"valid": true
},
{
"description": "an invalid time string with invalid hour",
"data": "24:00:00Z",
"valid": false
},
{
"description": "an invalid time string with invalid minute",
"data": "00:60:00Z",
"valid": false
},
{
"description": "an invalid time string with invalid second",
"data": "00:00:61Z",
"valid": false
},
{
"description": "an invalid time string with invalid leap second (wrong hour)",
"data": "22:59:60Z",
"valid": false
},
{
"description": "an invalid time string with invalid leap second (wrong minute)",
"data": "23:58:60Z",
"valid": false
},
{
"description": "an invalid time string with invalid time numoffset hour",
"data": "01:02:03+24:00",
"valid": false
},
{
"description": "an invalid time string with invalid time numoffset minute",
"data": "01:02:03+00:60",
"valid": false
},
{
"description": "an invalid time string with invalid time with both Z and numoffset",
"data": "01:02:03Z+00:30",
"valid": false
},
{
"description": "an invalid offset indicator",
"data": "08:30:06 PST",
"valid": false
},
{
"description": "only RFC3339 not all of ISO 8601 are valid",
"data": "01:01:01,1111",
"valid": false
},
{
"description": "no time offset",
"data": "12:00:00",
"valid": false
},
{
"description": "no time offset with second fraction",
"data": "12:00:00.52",
"valid": false
},
{
"description": "invalid non-ASCII '২' (a Bengali 2)",
"data": "1২:00:00Z",
"valid": false
},
{
"description": "offset not starting with plus or minus",
"data": "08:30:06#00:20",
"valid": false
},
{
"description": "contains letters",
"data": "ab:cd:ef",
"valid": false
},
{
"description": "an invalid time string in date-time format",
"data": "2020-11-28T23:55:45Z",
"valid": false
}
]
}
]
@@ -0,0 +1,46 @@
[
{
"description": "unknown format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "unknown"
},
"tests": [
{
"description": "unknown formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "unknown formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "unknown formats ignore objects",
"data": {},
"valid": true
},
{
"description": "unknown formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "unknown formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "unknown formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "unknown formats ignore strings",
"data": "string",
"valid": true
}
]
}
]
@@ -0,0 +1,86 @@
[
{
"description": "validation of URI References",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "uri-reference"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid URI",
"data": "http://foo.bar/?baz=qux#quux",
"valid": true
},
{
"description": "a valid protocol-relative URI Reference",
"data": "//foo.bar/?baz=qux#quux",
"valid": true
},
{
"description": "a valid relative URI Reference",
"data": "/abc",
"valid": true
},
{
"description": "an invalid URI Reference",
"data": "\\\\WINDOWS\\fileshare",
"valid": false
},
{
"description": "a valid URI Reference",
"data": "abc",
"valid": true
},
{
"description": "a valid URI fragment",
"data": "#fragment",
"valid": true
},
{
"description": "an invalid URI fragment",
"data": "#frag\\ment",
"valid": false
},
{
"description": "unescaped non US-ASCII characters",
"data": "/foobar®.txt",
"valid": false
},
{
"description": "invalid backslash character",
"data": "https://example.org/foobar\\.txt",
"valid": false
}
]
}
]
@@ -0,0 +1,61 @@
[
{
"description": "format: uri-template",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "uri-template"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid uri-template",
"data": "http://example.com/dictionary/{term:1}/{term}",
"valid": true
},
{
"description": "an invalid uri-template",
"data": "http://example.com/dictionary/{term:1}/{term",
"valid": false
},
{
"description": "a valid uri-template without variables",
"data": "http://example.com/dictionary",
"valid": true
},
{
"description": "a valid relative uri-template",
"data": "dictionary/{term:1}/{term}",
"valid": true
}
]
}
]
@@ -0,0 +1,191 @@
[
{
"description": "validation of URIs",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "uri"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "a valid URL with anchor tag",
"data": "http://foo.bar/?baz=qux#quux",
"valid": true
},
{
"description": "a valid URL with anchor tag and parentheses",
"data": "http://foo.com/blah_(wikipedia)_blah#cite-1",
"valid": true
},
{
"description": "a valid URL with URL-encoded stuff",
"data": "http://foo.bar/?q=Test%20URL-encoded%20stuff",
"valid": true
},
{
"description": "a valid puny-coded URL ",
"data": "http://xn--nw2a.xn--j6w193g/",
"valid": true
},
{
"description": "a valid URL with many special characters",
"data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com",
"valid": true
},
{
"description": "a valid URL based on IPv4",
"data": "http://223.255.255.254",
"valid": true
},
{
"description": "a valid URL with ftp scheme",
"data": "ftp://ftp.is.co.za/rfc/rfc1808.txt",
"valid": true
},
{
"description": "a valid URL for a simple text file",
"data": "http://www.ietf.org/rfc/rfc2396.txt",
"valid": true
},
{
"description": "a valid URL ",
"data": "ldap://[2001:db8::7]/c=GB?objectClass?one",
"valid": true
},
{
"description": "a valid mailto URI",
"data": "mailto:John.Doe@example.com",
"valid": true
},
{
"description": "a valid newsgroup URI",
"data": "news:comp.infosystems.www.servers.unix",
"valid": true
},
{
"description": "a valid tel URI",
"data": "tel:+1-816-555-1212",
"valid": true
},
{
"description": "a valid URN",
"data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2",
"valid": true
},
{
"description": "an invalid protocol-relative URI Reference",
"data": "//foo.bar/?baz=qux#quux",
"valid": false
},
{
"description": "an invalid relative URI Reference",
"data": "/abc",
"valid": false
},
{
"description": "an invalid URI",
"data": "\\\\WINDOWS\\fileshare",
"valid": false
},
{
"description": "an invalid URI though valid URI reference",
"data": "abc",
"valid": false
},
{
"description": "an invalid URI with spaces",
"data": "http:// shouldfail.com",
"valid": false
},
{
"description": "an invalid URI with spaces and missing scheme",
"data": ":// should fail",
"valid": false
},
{
"description": "an invalid URI with comma in scheme",
"data": "bar,baz:foo",
"valid": false
},
{
"description": "invalid userinfo",
"data": "https://[@example.org/test.txt",
"valid": false
},
{
"description": "unescaped non US-ASCII characters",
"data": "https://example.org/foobar®.txt",
"valid": false
},
{
"description": "invalid backslash character",
"data": "https://example.org/foobar\\.txt",
"valid": false
},
{
"description": "invalid \" character",
"data": "https://example.org/foobar\".txt",
"valid": false
},
{
"description": "invalid <> characters",
"data": "https://example.org/foobar<>.txt",
"valid": false
},
{
"description": "invalid {} characters",
"data": "https://example.org/foobar{}.txt",
"valid": false
},
{
"description": "invalid ^ character",
"data": "https://example.org/foobar^.txt",
"valid": false
},
{
"description": "invalid ` character",
"data": "https://example.org/foobar`.txt",
"valid": false
},
{
"description": "invalid SPACE character",
"data": "https://example.org/foo bar.txt",
"valid": false
},
{
"description": "invalid | character",
"data": "https://example.org/foobar|.txt",
"valid": false
}
]
}
]
@@ -0,0 +1,121 @@
[
{
"description": "uuid format",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "uuid"
},
"tests": [
{
"description": "all string formats ignore integers",
"data": 12,
"valid": true
},
{
"description": "all string formats ignore floats",
"data": 13.7,
"valid": true
},
{
"description": "all string formats ignore objects",
"data": {},
"valid": true
},
{
"description": "all string formats ignore arrays",
"data": [],
"valid": true
},
{
"description": "all string formats ignore booleans",
"data": false,
"valid": true
},
{
"description": "all string formats ignore nulls",
"data": null,
"valid": true
},
{
"description": "all upper-case",
"data": "2EB8AA08-AA98-11EA-B4AA-73B441D16380",
"valid": true
},
{
"description": "all lower-case",
"data": "2eb8aa08-aa98-11ea-b4aa-73b441d16380",
"valid": true
},
{
"description": "mixed case",
"data": "2eb8aa08-AA98-11ea-B4Aa-73B441D16380",
"valid": true
},
{
"description": "all zeroes is valid",
"data": "00000000-0000-0000-0000-000000000000",
"valid": true
},
{
"description": "wrong length",
"data": "2eb8aa08-aa98-11ea-b4aa-73b441d1638",
"valid": false
},
{
"description": "missing section",
"data": "2eb8aa08-aa98-11ea-73b441d16380",
"valid": false
},
{
"description": "bad characters (not hex)",
"data": "2eb8aa08-aa98-11ea-b4ga-73b441d16380",
"valid": false
},
{
"description": "no dashes",
"data": "2eb8aa08aa9811eab4aa73b441d16380",
"valid": false
},
{
"description": "too few dashes",
"data": "2eb8aa08aa98-11ea-b4aa73b441d16380",
"valid": false
},
{
"description": "too many dashes",
"data": "2eb8-aa08-aa98-11ea-b4aa73b44-1d16380",
"valid": false
},
{
"description": "dashes in the wrong spot",
"data": "2eb8aa08aa9811eab4aa73b441d16380----",
"valid": false
},
{
"description": "shifted dashes",
"data": "2eb8aa0-8aa98-11e-ab4aa7-3b441d16380",
"valid": false
},
{
"description": "valid version 4",
"data": "98d80576-482e-427f-8434-7f86890ab222",
"valid": true
},
{
"description": "valid version 5",
"data": "99c17cbb-656f-564a-940f-1a4568f03487",
"valid": true
},
{
"description": "hypothetical version 6",
"data": "99c17cbb-656f-664a-940f-1a4568f03487",
"valid": true
},
{
"description": "hypothetical version 15",
"data": "99c17cbb-656f-f64a-940f-1a4568f03487",
"valid": true
}
]
}
]
@@ -0,0 +1,53 @@
[
{
"description": "$id inside an enum is not a real identifier",
"comment": "the implementation must not be confused by an $id buried in the enum",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$defs": {
"id_in_enum": {
"enum": [
{
"$id": "https://localhost:1234/draft2020-12/id/my_identifier.json",
"type": "null"
}
]
},
"real_id_in_schema": {
"$id": "https://localhost:1234/draft2020-12/id/my_identifier.json",
"type": "string"
},
"zzz_id_in_const": {
"const": {
"$id": "https://localhost:1234/draft2020-12/id/my_identifier.json",
"type": "null"
}
}
},
"anyOf": [
{ "$ref": "#/$defs/id_in_enum" },
{ "$ref": "https://localhost:1234/draft2020-12/id/my_identifier.json" }
]
},
"tests": [
{
"description": "exact match to enum, and type matches",
"data": {
"$id": "https://localhost:1234/draft2020-12/id/my_identifier.json",
"type": "null"
},
"valid": true
},
{
"description": "match $ref to $id",
"data": "a string to match #/$defs/id_in_enum",
"valid": true
},
{
"description": "no match on enum or $ref to $id",
"data": 1,
"valid": false
}
]
}
]
@@ -0,0 +1,26 @@
[
{
"description": "validation without $schema",
"comment": "minLength is the same across all drafts",
"schema": {
"minLength": 2
},
"tests": [
{
"description": "a 3-character string is valid",
"data": "foo",
"valid": true
},
{
"description": "a 1-character string is not valid",
"data": "a",
"valid": false
},
{
"description": "a non-string is valid",
"data": 5,
"valid": true
}
]
}
]
@@ -0,0 +1,86 @@
[
{
"description": "Proper UTF-16 surrogate pair handling: pattern",
"comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"pattern": "^🐲*$"
},
"tests": [
{
"description": "matches empty",
"data": "",
"valid": true
},
{
"description": "matches single",
"data": "🐲",
"valid": true
},
{
"description": "matches two",
"data": "🐲🐲",
"valid": true
},
{
"description": "doesn't match one",
"data": "🐉",
"valid": false
},
{
"description": "doesn't match two",
"data": "🐉🐉",
"valid": false
},
{
"description": "doesn't match one ASCII",
"data": "D",
"valid": false
},
{
"description": "doesn't match two ASCII",
"data": "DD",
"valid": false
}
]
},
{
"description": "Proper UTF-16 surrogate pair handling: patternProperties",
"comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"patternProperties": {
"^🐲*$": {
"type": "integer"
}
}
},
"tests": [
{
"description": "matches empty",
"data": { "": 1 },
"valid": true
},
{
"description": "matches single",
"data": { "🐲": 1 },
"valid": true
},
{
"description": "matches two",
"data": { "🐲🐲": 1 },
"valid": true
},
{
"description": "doesn't match one",
"data": { "🐲": "hello" },
"valid": false
},
{
"description": "doesn't match two",
"data": { "🐲🐲": "hello" },
"valid": false
}
]
}
]
@@ -0,0 +1,113 @@
[
{
"description": "reference of a root arbitrary keyword ",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"unknown-keyword": {"type": "integer"},
"properties": {
"bar": {"$ref": "#/unknown-keyword"}
}
},
"tests": [
{
"description": "match",
"data": {"bar": 3},
"valid": true
},
{
"description": "mismatch",
"data": {"bar": true},
"valid": false
}
]
},
{
"description": "reference of a root arbitrary keyword with encoded ref",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"unknown/keyword": {"type": "integer"},
"properties": {
"bar": {"$ref": "#/unknown~1keyword"}
}
},
"tests": [
{
"description": "match",
"data": {"bar": 3},
"valid": true
},
{
"description": "mismatch",
"data": {"bar": true},
"valid": false
}
]
},
{
"description": "reference of an arbitrary keyword of a sub-schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": {"unknown-keyword": {"type": "integer"}},
"bar": {"$ref": "#/properties/foo/unknown-keyword"}
}
},
"tests": [
{
"description": "match",
"data": {"bar": 3},
"valid": true
},
{
"description": "mismatch",
"data": {"bar": true},
"valid": false
}
]
},
{
"description": "reference internals of known non-applicator",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "/base",
"examples": [
{ "type": "string" }
],
"$ref": "#/examples/0"
},
"tests": [
{
"description": "match",
"data": "a string",
"valid": true
},
{
"description": "mismatch",
"data": 42,
"valid": false
}
]
},
{
"description": "reference of an arbitrary keyword of a sub-schema with encoded ref",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": {"unknown/keyword": {"type": "integer"}},
"bar": {"$ref": "#/properties/foo/unknown~1keyword"}
}
},
"tests": [
{
"description": "match",
"data": {"bar": 3},
"valid": true
},
{
"description": "mismatch",
"data": {"bar": true},
"valid": false
}
]
}
]
@@ -0,0 +1,57 @@
[
{
"description": "$id inside an unknown keyword is not a real identifier",
"comment": "the implementation must not be confused by an $id in locations we do not know how to parse",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$defs": {
"id_in_unknown0": {
"not": {
"array_of_schemas": [
{
"$id": "https://localhost:1234/draft2020-12/unknownKeyword/my_identifier.json",
"type": "null"
}
]
}
},
"real_id_in_schema": {
"$id": "https://localhost:1234/draft2020-12/unknownKeyword/my_identifier.json",
"type": "string"
},
"id_in_unknown1": {
"not": {
"object_of_schemas": {
"foo": {
"$id": "https://localhost:1234/draft2020-12/unknownKeyword/my_identifier.json",
"type": "integer"
}
}
}
}
},
"anyOf": [
{ "$ref": "#/$defs/id_in_unknown0" },
{ "$ref": "#/$defs/id_in_unknown1" },
{ "$ref": "https://localhost:1234/draft2020-12/unknownKeyword/my_identifier.json" }
]
},
"tests": [
{
"description": "type matches second anyOf, which has a real schema in it",
"data": "a string",
"valid": true
},
{
"description": "type matches non-schema in first anyOf",
"data": null,
"valid": false
},
{
"description": "type matches non-schema in third anyOf",
"data": 1,
"valid": false
}
]
}
]
@@ -0,0 +1,65 @@
[
{
"description": "pattern validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"pattern": "^a*$"
},
"tests": [
{
"description": "a matching pattern is valid",
"data": "aaa",
"valid": true
},
{
"description": "a non-matching pattern is invalid",
"data": "abc",
"valid": false
},
{
"description": "ignores booleans",
"data": true,
"valid": true
},
{
"description": "ignores integers",
"data": 123,
"valid": true
},
{
"description": "ignores floats",
"data": 1.0,
"valid": true
},
{
"description": "ignores objects",
"data": {},
"valid": true
},
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores null",
"data": null,
"valid": true
}
]
},
{
"description": "pattern is not anchored",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"pattern": "a+"
},
"tests": [
{
"description": "matches a substring",
"data": "xxaayy",
"valid": true
}
]
}
]
@@ -0,0 +1,176 @@
[
{
"description":
"patternProperties validates properties matching a regex",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"patternProperties": {
"f.*o": {"type": "integer"}
}
},
"tests": [
{
"description": "a single valid match is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "multiple valid matches is valid",
"data": {"foo": 1, "foooooo" : 2},
"valid": true
},
{
"description": "a single invalid match is invalid",
"data": {"foo": "bar", "fooooo": 2},
"valid": false
},
{
"description": "multiple invalid matches is invalid",
"data": {"foo": "bar", "foooooo" : "baz"},
"valid": false
},
{
"description": "ignores arrays",
"data": ["foo"],
"valid": true
},
{
"description": "ignores strings",
"data": "foo",
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
}
]
},
{
"description": "multiple simultaneous patternProperties are validated",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"patternProperties": {
"a*": {"type": "integer"},
"aaa*": {"maximum": 20}
}
},
"tests": [
{
"description": "a single valid match is valid",
"data": {"a": 21},
"valid": true
},
{
"description": "a simultaneous match is valid",
"data": {"aaaa": 18},
"valid": true
},
{
"description": "multiple matches is valid",
"data": {"a": 21, "aaaa": 18},
"valid": true
},
{
"description": "an invalid due to one is invalid",
"data": {"a": "bar"},
"valid": false
},
{
"description": "an invalid due to the other is invalid",
"data": {"aaaa": 31},
"valid": false
},
{
"description": "an invalid due to both is invalid",
"data": {"aaa": "foo", "aaaa": 31},
"valid": false
}
]
},
{
"description": "regexes are not anchored by default and are case sensitive",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"patternProperties": {
"[0-9]{2,}": { "type": "boolean" },
"X_": { "type": "string" }
}
},
"tests": [
{
"description": "non recognized members are ignored",
"data": { "answer 1": "42" },
"valid": true
},
{
"description": "recognized members are accounted for",
"data": { "a31b": null },
"valid": false
},
{
"description": "regexes are case sensitive",
"data": { "a_x_3": 3 },
"valid": true
},
{
"description": "regexes are case sensitive, 2",
"data": { "a_X_3": 3 },
"valid": false
}
]
},
{
"description": "patternProperties with boolean schemas",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"patternProperties": {
"f.*": true,
"b.*": false
}
},
"tests": [
{
"description": "object with property matching schema true is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "object with property matching schema false is invalid",
"data": {"bar": 2},
"valid": false
},
{
"description": "object with both properties is invalid",
"data": {"foo": 1, "bar": 2},
"valid": false
},
{
"description": "object with a property matching both true and false is invalid",
"data": {"foobar":1},
"valid": false
},
{
"description": "empty object is valid",
"data": {},
"valid": true
}
]
},
{
"description": "patternProperties with null valued instance properties",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"patternProperties": {
"^.*bar$": {"type": "null"}
}
},
"tests": [
{
"description": "allows null values",
"data": {"foobar": null},
"valid": true
}
]
}
]
@@ -0,0 +1,104 @@
[
{
"description": "a schema given for prefixItems",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [
{"type": "integer"},
{"type": "string"}
]
},
"tests": [
{
"description": "correct types",
"data": [ 1, "foo" ],
"valid": true
},
{
"description": "wrong types",
"data": [ "foo", 1 ],
"valid": false
},
{
"description": "incomplete array of items",
"data": [ 1 ],
"valid": true
},
{
"description": "array with additional items",
"data": [ 1, "foo", true ],
"valid": true
},
{
"description": "empty array",
"data": [ ],
"valid": true
},
{
"description": "JavaScript pseudo-array is valid",
"data": {
"0": "invalid",
"1": "valid",
"length": 2
},
"valid": true
}
]
},
{
"description": "prefixItems with boolean schemas",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [true, false]
},
"tests": [
{
"description": "array with one item is valid",
"data": [ 1 ],
"valid": true
},
{
"description": "array with two items is invalid",
"data": [ 1, "foo" ],
"valid": false
},
{
"description": "empty array is valid",
"data": [],
"valid": true
}
]
},
{
"description": "additional items are allowed by default",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [{"type": "integer"}]
},
"tests": [
{
"description": "only the first item is validated",
"data": [1, "foo", false],
"valid": true
}
]
},
{
"description": "prefixItems with null instance elements",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [
{
"type": "null"
}
]
},
"tests": [
{
"description": "allows null elements",
"data": [ null ],
"valid": true
}
]
}
]
@@ -0,0 +1,242 @@
[
{
"description": "object properties validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": {"type": "integer"},
"bar": {"type": "string"}
}
},
"tests": [
{
"description": "both properties present and valid is valid",
"data": {"foo": 1, "bar": "baz"},
"valid": true
},
{
"description": "one property invalid is invalid",
"data": {"foo": 1, "bar": {}},
"valid": false
},
{
"description": "both properties invalid is invalid",
"data": {"foo": [], "bar": {}},
"valid": false
},
{
"description": "doesn't invalidate other properties",
"data": {"quux": []},
"valid": true
},
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
}
]
},
{
"description":
"properties, patternProperties, additionalProperties interaction",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": {"type": "array", "maxItems": 3},
"bar": {"type": "array"}
},
"patternProperties": {"f.o": {"minItems": 2}},
"additionalProperties": {"type": "integer"}
},
"tests": [
{
"description": "property validates property",
"data": {"foo": [1, 2]},
"valid": true
},
{
"description": "property invalidates property",
"data": {"foo": [1, 2, 3, 4]},
"valid": false
},
{
"description": "patternProperty invalidates property",
"data": {"foo": []},
"valid": false
},
{
"description": "patternProperty validates nonproperty",
"data": {"fxo": [1, 2]},
"valid": true
},
{
"description": "patternProperty invalidates nonproperty",
"data": {"fxo": []},
"valid": false
},
{
"description": "additionalProperty ignores property",
"data": {"bar": []},
"valid": true
},
{
"description": "additionalProperty validates others",
"data": {"quux": 3},
"valid": true
},
{
"description": "additionalProperty invalidates others",
"data": {"quux": "foo"},
"valid": false
}
]
},
{
"description": "properties with boolean schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": true,
"bar": false
}
},
"tests": [
{
"description": "no property present is valid",
"data": {},
"valid": true
},
{
"description": "only 'true' property present is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "only 'false' property present is invalid",
"data": {"bar": 2},
"valid": false
},
{
"description": "both properties present is invalid",
"data": {"foo": 1, "bar": 2},
"valid": false
}
]
},
{
"description": "properties with escaped characters",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo\nbar": {"type": "number"},
"foo\"bar": {"type": "number"},
"foo\\bar": {"type": "number"},
"foo\rbar": {"type": "number"},
"foo\tbar": {"type": "number"},
"foo\fbar": {"type": "number"}
}
},
"tests": [
{
"description": "object with all numbers is valid",
"data": {
"foo\nbar": 1,
"foo\"bar": 1,
"foo\\bar": 1,
"foo\rbar": 1,
"foo\tbar": 1,
"foo\fbar": 1
},
"valid": true
},
{
"description": "object with strings is invalid",
"data": {
"foo\nbar": "1",
"foo\"bar": "1",
"foo\\bar": "1",
"foo\rbar": "1",
"foo\tbar": "1",
"foo\fbar": "1"
},
"valid": false
}
]
},
{
"description": "properties with null valued instance properties",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": {"type": "null"}
}
},
"tests": [
{
"description": "allows null values",
"data": {"foo": null},
"valid": true
}
]
},
{
"description": "properties whose names are Javascript object property names",
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"__proto__": {"type": "number"},
"toString": {
"properties": { "length": { "type": "string" } }
},
"constructor": {"type": "number"}
}
},
"tests": [
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
},
{
"description": "none of the properties mentioned",
"data": {},
"valid": true
},
{
"description": "__proto__ not valid",
"data": { "__proto__": "foo" },
"valid": false
},
{
"description": "toString not valid",
"data": { "toString": { "length": 37 } },
"valid": false
},
{
"description": "constructor not valid",
"data": { "constructor": { "length": 37 } },
"valid": false
},
{
"description": "all present and valid",
"data": {
"__proto__": 12,
"toString": { "length": "foo" },
"constructor": 37
},
"valid": true
}
]
}
]
@@ -0,0 +1,168 @@
[
{
"description": "propertyNames validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"propertyNames": {"maxLength": 3}
},
"tests": [
{
"description": "all property names valid",
"data": {
"f": {},
"foo": {}
},
"valid": true
},
{
"description": "some property names invalid",
"data": {
"foo": {},
"foobar": {}
},
"valid": false
},
{
"description": "object without properties is valid",
"data": {},
"valid": true
},
{
"description": "ignores arrays",
"data": [1, 2, 3, 4],
"valid": true
},
{
"description": "ignores strings",
"data": "foobar",
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
}
]
},
{
"description": "propertyNames validation with pattern",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"propertyNames": { "pattern": "^a+$" }
},
"tests": [
{
"description": "matching property names valid",
"data": {
"a": {},
"aa": {},
"aaa": {}
},
"valid": true
},
{
"description": "non-matching property name is invalid",
"data": {
"aaA": {}
},
"valid": false
},
{
"description": "object without properties is valid",
"data": {},
"valid": true
}
]
},
{
"description": "propertyNames with boolean schema true",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"propertyNames": true
},
"tests": [
{
"description": "object with any properties is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "empty object is valid",
"data": {},
"valid": true
}
]
},
{
"description": "propertyNames with boolean schema false",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"propertyNames": false
},
"tests": [
{
"description": "object with any properties is invalid",
"data": {"foo": 1},
"valid": false
},
{
"description": "empty object is valid",
"data": {},
"valid": true
}
]
},
{
"description": "propertyNames with const",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"propertyNames": {"const": "foo"}
},
"tests": [
{
"description": "object with property foo is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "object with any other property is invalid",
"data": {"bar": 1},
"valid": false
},
{
"description": "empty object is valid",
"data": {},
"valid": true
}
]
},
{
"description": "propertyNames with enum",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"propertyNames": {"enum": ["foo", "bar"]}
},
"tests": [
{
"description": "object with property foo is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "object with property foo and bar is valid",
"data": {"foo": 1, "bar": 1},
"valid": true
},
{
"description": "object with any other property is invalid",
"data": {"baz": 1},
"valid": false
},
{
"description": "empty object is valid",
"data": {},
"valid": true
}
]
}
]
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,342 @@
[
{
"description": "remote ref",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "http://localhost:1234/draft2020-12/integer.json"
},
"tests": [
{
"description": "remote ref valid",
"data": 1,
"valid": true
},
{
"description": "remote ref invalid",
"data": "a",
"valid": false
}
]
},
{
"description": "fragment within remote ref",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "http://localhost:1234/draft2020-12/subSchemas.json#/$defs/integer"
},
"tests": [
{
"description": "remote fragment valid",
"data": 1,
"valid": true
},
{
"description": "remote fragment invalid",
"data": "a",
"valid": false
}
]
},
{
"description": "anchor within remote ref",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "http://localhost:1234/draft2020-12/locationIndependentIdentifier.json#foo"
},
"tests": [
{
"description": "remote anchor valid",
"data": 1,
"valid": true
},
{
"description": "remote anchor invalid",
"data": "a",
"valid": false
}
]
},
{
"description": "ref within remote ref",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "http://localhost:1234/draft2020-12/subSchemas.json#/$defs/refToInteger"
},
"tests": [
{
"description": "ref within ref valid",
"data": 1,
"valid": true
},
{
"description": "ref within ref invalid",
"data": "a",
"valid": false
}
]
},
{
"description": "base URI change",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://localhost:1234/draft2020-12/",
"items": {
"$id": "baseUriChange/",
"items": {"$ref": "folderInteger.json"}
}
},
"tests": [
{
"description": "base URI change ref valid",
"data": [[1]],
"valid": true
},
{
"description": "base URI change ref invalid",
"data": [["a"]],
"valid": false
}
]
},
{
"description": "base URI change - change folder",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://localhost:1234/draft2020-12/scope_change_defs1.json",
"type" : "object",
"properties": {"list": {"$ref": "baseUriChangeFolder/"}},
"$defs": {
"baz": {
"$id": "baseUriChangeFolder/",
"type": "array",
"items": {"$ref": "folderInteger.json"}
}
}
},
"tests": [
{
"description": "number is valid",
"data": {"list": [1]},
"valid": true
},
{
"description": "string is invalid",
"data": {"list": ["a"]},
"valid": false
}
]
},
{
"description": "base URI change - change folder in subschema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://localhost:1234/draft2020-12/scope_change_defs2.json",
"type" : "object",
"properties": {"list": {"$ref": "baseUriChangeFolderInSubschema/#/$defs/bar"}},
"$defs": {
"baz": {
"$id": "baseUriChangeFolderInSubschema/",
"$defs": {
"bar": {
"type": "array",
"items": {"$ref": "folderInteger.json"}
}
}
}
}
},
"tests": [
{
"description": "number is valid",
"data": {"list": [1]},
"valid": true
},
{
"description": "string is invalid",
"data": {"list": ["a"]},
"valid": false
}
]
},
{
"description": "root ref in remote ref",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://localhost:1234/draft2020-12/object",
"type": "object",
"properties": {
"name": {"$ref": "name-defs.json#/$defs/orNull"}
}
},
"tests": [
{
"description": "string is valid",
"data": {
"name": "foo"
},
"valid": true
},
{
"description": "null is valid",
"data": {
"name": null
},
"valid": true
},
{
"description": "object is invalid",
"data": {
"name": {
"name": null
}
},
"valid": false
}
]
},
{
"description": "remote ref with ref to defs",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://localhost:1234/draft2020-12/schema-remote-ref-ref-defs1.json",
"$ref": "ref-and-defs.json"
},
"tests": [
{
"description": "invalid",
"data": {
"bar": 1
},
"valid": false
},
{
"description": "valid",
"data": {
"bar": "a"
},
"valid": true
}
]
},
{
"description": "Location-independent identifier in remote ref",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "http://localhost:1234/draft2020-12/locationIndependentIdentifier.json#/$defs/refToInteger"
},
"tests": [
{
"description": "integer is valid",
"data": 1,
"valid": true
},
{
"description": "string is invalid",
"data": "foo",
"valid": false
}
]
},
{
"description": "retrieved nested refs resolve relative to their URI not $id",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://localhost:1234/draft2020-12/some-id",
"properties": {
"name": {"$ref": "nested/foo-ref-string.json"}
}
},
"tests": [
{
"description": "number is invalid",
"data": {
"name": {"foo": 1}
},
"valid": false
},
{
"description": "string is valid",
"data": {
"name": {"foo": "a"}
},
"valid": true
}
]
},
{
"description": "remote HTTP ref with different $id",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "http://localhost:1234/different-id-ref-string.json"
},
"tests": [
{
"description": "number is invalid",
"data": 1,
"valid": false
},
{
"description": "string is valid",
"data": "foo",
"valid": true
}
]
},
{
"description": "remote HTTP ref with different URN $id",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "http://localhost:1234/urn-ref-string.json"
},
"tests": [
{
"description": "number is invalid",
"data": 1,
"valid": false
},
{
"description": "string is valid",
"data": "foo",
"valid": true
}
]
},
{
"description": "remote HTTP ref with nested absolute ref",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"
},
"tests": [
{
"description": "number is invalid",
"data": 1,
"valid": false
},
{
"description": "string is valid",
"data": "foo",
"valid": true
}
]
},
{
"description": "$ref to $ref finds detached $anchor",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "http://localhost:1234/draft2020-12/detached-ref.json#/$defs/foo"
},
"tests": [
{
"description": "number is valid",
"data": 1,
"valid": true
},
{
"description": "non-number is invalid",
"data": "a",
"valid": false
}
]
}
]
@@ -0,0 +1,158 @@
[
{
"description": "required validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": {},
"bar": {}
},
"required": ["foo"]
},
"tests": [
{
"description": "present required property is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "non-present required property is invalid",
"data": {"bar": 1},
"valid": false
},
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores strings",
"data": "",
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
}
]
},
{
"description": "required default validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": {}
}
},
"tests": [
{
"description": "not required by default",
"data": {},
"valid": true
}
]
},
{
"description": "required with empty array",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": {}
},
"required": []
},
"tests": [
{
"description": "property not required",
"data": {},
"valid": true
}
]
},
{
"description": "required with escaped characters",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"required": [
"foo\nbar",
"foo\"bar",
"foo\\bar",
"foo\rbar",
"foo\tbar",
"foo\fbar"
]
},
"tests": [
{
"description": "object with all properties present is valid",
"data": {
"foo\nbar": 1,
"foo\"bar": 1,
"foo\\bar": 1,
"foo\rbar": 1,
"foo\tbar": 1,
"foo\fbar": 1
},
"valid": true
},
{
"description": "object with some properties missing is invalid",
"data": {
"foo\nbar": "1",
"foo\"bar": "1"
},
"valid": false
}
]
},
{
"description": "required properties whose names are Javascript object property names",
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"required": ["__proto__", "toString", "constructor"]
},
"tests": [
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
},
{
"description": "none of the properties mentioned",
"data": {},
"valid": false
},
{
"description": "__proto__ present",
"data": { "__proto__": "foo" },
"valid": false
},
{
"description": "toString present",
"data": { "toString": { "length": 37 } },
"valid": false
},
{
"description": "constructor present",
"data": { "constructor": { "length": 37 } },
"valid": false
},
{
"description": "all present",
"data": {
"__proto__": 12,
"toString": { "length": "foo" },
"constructor": 37
},
"valid": true
}
]
}
]
@@ -0,0 +1,501 @@
[
{
"description": "integer type matches integers",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "integer"
},
"tests": [
{
"description": "an integer is an integer",
"data": 1,
"valid": true
},
{
"description": "a float with zero fractional part is an integer",
"data": 1.0,
"valid": true
},
{
"description": "a float is not an integer",
"data": 1.1,
"valid": false
},
{
"description": "a string is not an integer",
"data": "foo",
"valid": false
},
{
"description": "a string is still not an integer, even if it looks like one",
"data": "1",
"valid": false
},
{
"description": "an object is not an integer",
"data": {},
"valid": false
},
{
"description": "an array is not an integer",
"data": [],
"valid": false
},
{
"description": "a boolean is not an integer",
"data": true,
"valid": false
},
{
"description": "null is not an integer",
"data": null,
"valid": false
}
]
},
{
"description": "number type matches numbers",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "number"
},
"tests": [
{
"description": "an integer is a number",
"data": 1,
"valid": true
},
{
"description": "a float with zero fractional part is a number (and an integer)",
"data": 1.0,
"valid": true
},
{
"description": "a float is a number",
"data": 1.1,
"valid": true
},
{
"description": "a string is not a number",
"data": "foo",
"valid": false
},
{
"description": "a string is still not a number, even if it looks like one",
"data": "1",
"valid": false
},
{
"description": "an object is not a number",
"data": {},
"valid": false
},
{
"description": "an array is not a number",
"data": [],
"valid": false
},
{
"description": "a boolean is not a number",
"data": true,
"valid": false
},
{
"description": "null is not a number",
"data": null,
"valid": false
}
]
},
{
"description": "string type matches strings",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string"
},
"tests": [
{
"description": "1 is not a string",
"data": 1,
"valid": false
},
{
"description": "a float is not a string",
"data": 1.1,
"valid": false
},
{
"description": "a string is a string",
"data": "foo",
"valid": true
},
{
"description": "a string is still a string, even if it looks like a number",
"data": "1",
"valid": true
},
{
"description": "an empty string is still a string",
"data": "",
"valid": true
},
{
"description": "an object is not a string",
"data": {},
"valid": false
},
{
"description": "an array is not a string",
"data": [],
"valid": false
},
{
"description": "a boolean is not a string",
"data": true,
"valid": false
},
{
"description": "null is not a string",
"data": null,
"valid": false
}
]
},
{
"description": "object type matches objects",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object"
},
"tests": [
{
"description": "an integer is not an object",
"data": 1,
"valid": false
},
{
"description": "a float is not an object",
"data": 1.1,
"valid": false
},
{
"description": "a string is not an object",
"data": "foo",
"valid": false
},
{
"description": "an object is an object",
"data": {},
"valid": true
},
{
"description": "an array is not an object",
"data": [],
"valid": false
},
{
"description": "a boolean is not an object",
"data": true,
"valid": false
},
{
"description": "null is not an object",
"data": null,
"valid": false
}
]
},
{
"description": "array type matches arrays",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array"
},
"tests": [
{
"description": "an integer is not an array",
"data": 1,
"valid": false
},
{
"description": "a float is not an array",
"data": 1.1,
"valid": false
},
{
"description": "a string is not an array",
"data": "foo",
"valid": false
},
{
"description": "an object is not an array",
"data": {},
"valid": false
},
{
"description": "an array is an array",
"data": [],
"valid": true
},
{
"description": "a boolean is not an array",
"data": true,
"valid": false
},
{
"description": "null is not an array",
"data": null,
"valid": false
}
]
},
{
"description": "boolean type matches booleans",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "boolean"
},
"tests": [
{
"description": "an integer is not a boolean",
"data": 1,
"valid": false
},
{
"description": "zero is not a boolean",
"data": 0,
"valid": false
},
{
"description": "a float is not a boolean",
"data": 1.1,
"valid": false
},
{
"description": "a string is not a boolean",
"data": "foo",
"valid": false
},
{
"description": "an empty string is not a boolean",
"data": "",
"valid": false
},
{
"description": "an object is not a boolean",
"data": {},
"valid": false
},
{
"description": "an array is not a boolean",
"data": [],
"valid": false
},
{
"description": "true is a boolean",
"data": true,
"valid": true
},
{
"description": "false is a boolean",
"data": false,
"valid": true
},
{
"description": "null is not a boolean",
"data": null,
"valid": false
}
]
},
{
"description": "null type matches only the null object",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "null"
},
"tests": [
{
"description": "an integer is not null",
"data": 1,
"valid": false
},
{
"description": "a float is not null",
"data": 1.1,
"valid": false
},
{
"description": "zero is not null",
"data": 0,
"valid": false
},
{
"description": "a string is not null",
"data": "foo",
"valid": false
},
{
"description": "an empty string is not null",
"data": "",
"valid": false
},
{
"description": "an object is not null",
"data": {},
"valid": false
},
{
"description": "an array is not null",
"data": [],
"valid": false
},
{
"description": "true is not null",
"data": true,
"valid": false
},
{
"description": "false is not null",
"data": false,
"valid": false
},
{
"description": "null is null",
"data": null,
"valid": true
}
]
},
{
"description": "multiple types can be specified in an array",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": ["integer", "string"]
},
"tests": [
{
"description": "an integer is valid",
"data": 1,
"valid": true
},
{
"description": "a string is valid",
"data": "foo",
"valid": true
},
{
"description": "a float is invalid",
"data": 1.1,
"valid": false
},
{
"description": "an object is invalid",
"data": {},
"valid": false
},
{
"description": "an array is invalid",
"data": [],
"valid": false
},
{
"description": "a boolean is invalid",
"data": true,
"valid": false
},
{
"description": "null is invalid",
"data": null,
"valid": false
}
]
},
{
"description": "type as array with one item",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": ["string"]
},
"tests": [
{
"description": "string is valid",
"data": "foo",
"valid": true
},
{
"description": "number is invalid",
"data": 123,
"valid": false
}
]
},
{
"description": "type: array or object",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": ["array", "object"]
},
"tests": [
{
"description": "array is valid",
"data": [1,2,3],
"valid": true
},
{
"description": "object is valid",
"data": {"foo": 123},
"valid": true
},
{
"description": "number is invalid",
"data": 123,
"valid": false
},
{
"description": "string is invalid",
"data": "foo",
"valid": false
},
{
"description": "null is invalid",
"data": null,
"valid": false
}
]
},
{
"description": "type: array, object or null",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": ["array", "object", "null"]
},
"tests": [
{
"description": "array is valid",
"data": [1,2,3],
"valid": true
},
{
"description": "object is valid",
"data": {"foo": 123},
"valid": true
},
{
"description": "null is valid",
"data": null,
"valid": true
},
{
"description": "number is invalid",
"data": 123,
"valid": false
},
{
"description": "string is invalid",
"data": "foo",
"valid": false
}
]
}
]
@@ -0,0 +1,854 @@
[
{
"description": "unevaluatedItems true",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"unevaluatedItems": true
},
"tests": [
{
"description": "with no unevaluated items",
"data": [],
"valid": true
},
{
"description": "with unevaluated items",
"data": ["foo"],
"valid": true
}
]
},
{
"description": "unevaluatedItems false",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"unevaluatedItems": false
},
"tests": [
{
"description": "with no unevaluated items",
"data": [],
"valid": true
},
{
"description": "with unevaluated items",
"data": ["foo"],
"valid": false
}
]
},
{
"description": "unevaluatedItems as schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"unevaluatedItems": { "type": "string" }
},
"tests": [
{
"description": "with no unevaluated items",
"data": [],
"valid": true
},
{
"description": "with valid unevaluated items",
"data": ["foo"],
"valid": true
},
{
"description": "with invalid unevaluated items",
"data": [42],
"valid": false
}
]
},
{
"description": "unevaluatedItems with uniform items",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"items": { "type": "string" },
"unevaluatedItems": false
},
"tests": [
{
"description": "unevaluatedItems doesn't apply",
"data": ["foo", "bar"],
"valid": true
}
]
},
{
"description": "unevaluatedItems with tuple",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [
{ "type": "string" }
],
"unevaluatedItems": false
},
"tests": [
{
"description": "with no unevaluated items",
"data": ["foo"],
"valid": true
},
{
"description": "with unevaluated items",
"data": ["foo", "bar"],
"valid": false
}
]
},
{
"description": "unevaluatedItems with items and prefixItems",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [
{ "type": "string" }
],
"items": true,
"unevaluatedItems": false
},
"tests": [
{
"description": "unevaluatedItems doesn't apply",
"data": ["foo", 42],
"valid": true
}
]
},
{
"description": "unevaluatedItems with items",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"items": {"type": "number"},
"unevaluatedItems": {"type": "string"}
},
"tests": [
{
"description": "valid under items",
"comment": "no elements are considered by unevaluatedItems",
"data": [5, 6, 7, 8],
"valid": true
},
{
"description": "invalid under items",
"data": ["foo", "bar", "baz"],
"valid": false
}
]
},
{
"description": "unevaluatedItems with nested tuple",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [
{ "type": "string" }
],
"allOf": [
{
"prefixItems": [
true,
{ "type": "number" }
]
}
],
"unevaluatedItems": false
},
"tests": [
{
"description": "with no unevaluated items",
"data": ["foo", 42],
"valid": true
},
{
"description": "with unevaluated items",
"data": ["foo", 42, true],
"valid": false
}
]
},
{
"description": "unevaluatedItems with nested items",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"unevaluatedItems": {"type": "boolean"},
"anyOf": [
{ "items": {"type": "string"} },
true
]
},
"tests": [
{
"description": "with only (valid) additional items",
"data": [true, false],
"valid": true
},
{
"description": "with no additional items",
"data": ["yes", "no"],
"valid": true
},
{
"description": "with invalid additional item",
"data": ["yes", false],
"valid": false
}
]
},
{
"description": "unevaluatedItems with nested prefixItems and items",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{
"prefixItems": [
{ "type": "string" }
],
"items": true
}
],
"unevaluatedItems": false
},
"tests": [
{
"description": "with no additional items",
"data": ["foo"],
"valid": true
},
{
"description": "with additional items",
"data": ["foo", 42, true],
"valid": true
}
]
},
{
"description": "unevaluatedItems with nested unevaluatedItems",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{
"prefixItems": [
{ "type": "string" }
]
},
{ "unevaluatedItems": true }
],
"unevaluatedItems": false
},
"tests": [
{
"description": "with no additional items",
"data": ["foo"],
"valid": true
},
{
"description": "with additional items",
"data": ["foo", 42, true],
"valid": true
}
]
},
{
"description": "unevaluatedItems with anyOf",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [
{ "const": "foo" }
],
"anyOf": [
{
"prefixItems": [
true,
{ "const": "bar" }
]
},
{
"prefixItems": [
true,
true,
{ "const": "baz" }
]
}
],
"unevaluatedItems": false
},
"tests": [
{
"description": "when one schema matches and has no unevaluated items",
"data": ["foo", "bar"],
"valid": true
},
{
"description": "when one schema matches and has unevaluated items",
"data": ["foo", "bar", 42],
"valid": false
},
{
"description": "when two schemas match and has no unevaluated items",
"data": ["foo", "bar", "baz"],
"valid": true
},
{
"description": "when two schemas match and has unevaluated items",
"data": ["foo", "bar", "baz", 42],
"valid": false
}
]
},
{
"description": "unevaluatedItems with oneOf",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [
{ "const": "foo" }
],
"oneOf": [
{
"prefixItems": [
true,
{ "const": "bar" }
]
},
{
"prefixItems": [
true,
{ "const": "baz" }
]
}
],
"unevaluatedItems": false
},
"tests": [
{
"description": "with no unevaluated items",
"data": ["foo", "bar"],
"valid": true
},
{
"description": "with unevaluated items",
"data": ["foo", "bar", 42],
"valid": false
}
]
},
{
"description": "unevaluatedItems with not",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [
{ "const": "foo" }
],
"not": {
"not": {
"prefixItems": [
true,
{ "const": "bar" }
]
}
},
"unevaluatedItems": false
},
"tests": [
{
"description": "with unevaluated items",
"data": ["foo", "bar"],
"valid": false
}
]
},
{
"description": "unevaluatedItems with if/then/else",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [
{ "const": "foo" }
],
"if": {
"prefixItems": [
true,
{ "const": "bar" }
]
},
"then": {
"prefixItems": [
true,
true,
{ "const": "then" }
]
},
"else": {
"prefixItems": [
true,
true,
true,
{ "const": "else" }
]
},
"unevaluatedItems": false
},
"tests": [
{
"description": "when if matches and it has no unevaluated items",
"data": ["foo", "bar", "then"],
"valid": true
},
{
"description": "when if matches and it has unevaluated items",
"data": ["foo", "bar", "then", "else"],
"valid": false
},
{
"description": "when if doesn't match and it has no unevaluated items",
"data": ["foo", 42, 42, "else"],
"valid": true
},
{
"description": "when if doesn't match and it has unevaluated items",
"data": ["foo", 42, 42, "else", 42],
"valid": false
}
]
},
{
"description": "unevaluatedItems with boolean schemas",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [true],
"unevaluatedItems": false
},
"tests": [
{
"description": "with no unevaluated items",
"data": [],
"valid": true
},
{
"description": "with unevaluated items",
"data": ["foo"],
"valid": false
}
]
},
{
"description": "unevaluatedItems with $ref",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "#/$defs/bar",
"prefixItems": [
{ "type": "string" }
],
"unevaluatedItems": false,
"$defs": {
"bar": {
"prefixItems": [
true,
{ "type": "string" }
]
}
}
},
"tests": [
{
"description": "with no unevaluated items",
"data": ["foo", "bar"],
"valid": true
},
{
"description": "with unevaluated items",
"data": ["foo", "bar", "baz"],
"valid": false
}
]
},
{
"description": "unevaluatedItems before $ref",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"unevaluatedItems": false,
"prefixItems": [
{ "type": "string" }
],
"$ref": "#/$defs/bar",
"$defs": {
"bar": {
"prefixItems": [
true,
{ "type": "string" }
]
}
}
},
"tests": [
{
"description": "with no unevaluated items",
"data": ["foo", "bar"],
"valid": true
},
{
"description": "with unevaluated items",
"data": ["foo", "bar", "baz"],
"valid": false
}
]
},
{
"description": "unevaluatedItems with $dynamicRef",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/unevaluated-items-with-dynamic-ref/derived",
"$ref": "./baseSchema",
"$defs": {
"derived": {
"$dynamicAnchor": "addons",
"prefixItems": [
true,
{ "type": "string" }
]
},
"baseSchema": {
"$id": "./baseSchema",
"$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering",
"unevaluatedItems": false,
"type": "array",
"prefixItems": [
{ "type": "string" }
],
"$dynamicRef": "#addons",
"$defs": {
"defaultAddons": {
"$comment": "Needed to satisfy the bookending requirement",
"$dynamicAnchor": "addons"
}
}
}
}
},
"tests": [
{
"description": "with no unevaluated items",
"data": ["foo", "bar"],
"valid": true
},
{
"description": "with unevaluated items",
"data": ["foo", "bar", "baz"],
"valid": false
}
]
},
{
"description": "unevaluatedItems can't see inside cousins",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{
"prefixItems": [ true ]
},
{ "unevaluatedItems": false }
]
},
"tests": [
{
"description": "always fails",
"data": [ 1 ],
"valid": false
}
]
},
{
"description": "item is evaluated in an uncle schema to unevaluatedItems",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": {
"prefixItems": [
{ "type": "string" }
],
"unevaluatedItems": false
}
},
"anyOf": [
{
"properties": {
"foo": {
"prefixItems": [
true,
{ "type": "string" }
]
}
}
}
]
},
"tests": [
{
"description": "no extra items",
"data": {
"foo": [
"test"
]
},
"valid": true
},
{
"description": "uncle keyword evaluation is not significant",
"data": {
"foo": [
"test",
"test"
]
},
"valid": false
}
]
},
{
"description": "unevaluatedItems depends on adjacent contains",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [true],
"contains": {"type": "string"},
"unevaluatedItems": false
},
"tests": [
{
"description": "second item is evaluated by contains",
"data": [ 1, "foo" ],
"valid": true
},
{
"description": "contains fails, second item is not evaluated",
"data": [ 1, 2 ],
"valid": false
},
{
"description": "contains passes, second item is not evaluated",
"data": [ 1, 2, "foo" ],
"valid": false
}
]
},
{
"description": "unevaluatedItems depends on multiple nested contains",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
{ "contains": { "multipleOf": 2 } },
{ "contains": { "multipleOf": 3 } }
],
"unevaluatedItems": { "multipleOf": 5 }
},
"tests": [
{
"description": "5 not evaluated, passes unevaluatedItems",
"data": [ 2, 3, 4, 5, 6 ],
"valid": true
},
{
"description": "7 not evaluated, fails unevaluatedItems",
"data": [ 2, 3, 4, 7, 8 ],
"valid": false
}
]
},
{
"description": "unevaluatedItems and contains interact to control item dependency relationship",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"if": {
"contains": {"const": "a"}
},
"then": {
"if": {
"contains": {"const": "b"}
},
"then": {
"if": {
"contains": {"const": "c"}
}
}
},
"unevaluatedItems": false
},
"tests": [
{
"description": "empty array is valid",
"data": [],
"valid": true
},
{
"description": "only a's are valid",
"data": [ "a", "a" ],
"valid": true
},
{
"description": "a's and b's are valid",
"data": [ "a", "b", "a", "b", "a" ],
"valid": true
},
{
"description": "a's, b's and c's are valid",
"data": [ "c", "a", "c", "c", "b", "a" ],
"valid": true
},
{
"description": "only b's are invalid",
"data": [ "b", "b" ],
"valid": false
},
{
"description": "only c's are invalid",
"data": [ "c", "c" ],
"valid": false
},
{
"description": "only b's and c's are invalid",
"data": [ "c", "b", "c", "b", "c" ],
"valid": false
},
{
"description": "only a's and c's are invalid",
"data": [ "c", "a", "c", "a", "c" ],
"valid": false
}
]
},
{
"description" : "unevaluatedItems with minContains = 0",
"schema" : {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"contains": {"type": "string"},
"minContains": 0,
"unevaluatedItems": false
},
"tests" : [
{
"description": "empty array is valid",
"data": [],
"valid": true
},
{
"description": "no items evaluated by contains",
"data": [0],
"valid": false
},
{
"description": "some but not all items evaluated by contains",
"data": ["foo", 0],
"valid": false
},
{
"description": "all items evaluated by contains",
"data": ["foo", "bar"],
"valid": true
}
]
},
{
"description": "non-array instances are valid",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"unevaluatedItems": false
},
"tests": [
{
"description": "ignores booleans",
"data": true,
"valid": true
},
{
"description": "ignores integers",
"data": 123,
"valid": true
},
{
"description": "ignores floats",
"data": 1.0,
"valid": true
},
{
"description": "ignores objects",
"data": {},
"valid": true
},
{
"description": "ignores strings",
"data": "foo",
"valid": true
},
{
"description": "ignores null",
"data": null,
"valid": true
}
]
},
{
"description": "unevaluatedItems with null instance elements",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"unevaluatedItems": {
"type": "null"
}
},
"tests": [
{
"description": "allows null elements",
"data": [ null ],
"valid": true
}
]
},
{
"description": "unevaluatedItems can see annotations from if without then and else",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"if": {
"prefixItems": [{"const": "a"}]
},
"unevaluatedItems": false
},
"tests": [
{
"description": "valid in case if is evaluated",
"data": [ "a" ],
"valid": true
},
{
"description": "invalid in case if is evaluated",
"data": [ "b" ],
"valid": false
}
]
},
{
"description": "Evaluated items collection needs to consider instance location",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [
{
"prefixItems": [
true,
{ "type": "string" }
]
}
],
"unevaluatedItems": false
},
"tests": [
{
"description": "with an unevaluated item that exists at another location",
"data": [
["foo", "bar"],
"bar"
],
"valid": false
}
]
}
]
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,419 @@
[
{
"description": "uniqueItems validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"uniqueItems": true
},
"tests": [
{
"description": "unique array of integers is valid",
"data": [1, 2],
"valid": true
},
{
"description": "non-unique array of integers is invalid",
"data": [1, 1],
"valid": false
},
{
"description": "non-unique array of more than two integers is invalid",
"data": [1, 2, 1],
"valid": false
},
{
"description": "numbers are unique if mathematically unequal",
"data": [1.0, 1.00, 1],
"valid": false
},
{
"description": "false is not equal to zero",
"data": [0, false],
"valid": true
},
{
"description": "true is not equal to one",
"data": [1, true],
"valid": true
},
{
"description": "unique array of strings is valid",
"data": ["foo", "bar", "baz"],
"valid": true
},
{
"description": "non-unique array of strings is invalid",
"data": ["foo", "bar", "foo"],
"valid": false
},
{
"description": "unique array of objects is valid",
"data": [{"foo": "bar"}, {"foo": "baz"}],
"valid": true
},
{
"description": "non-unique array of objects is invalid",
"data": [{"foo": "bar"}, {"foo": "bar"}],
"valid": false
},
{
"description": "property order of array of objects is ignored",
"data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}],
"valid": false
},
{
"description": "unique array of nested objects is valid",
"data": [
{"foo": {"bar" : {"baz" : true}}},
{"foo": {"bar" : {"baz" : false}}}
],
"valid": true
},
{
"description": "non-unique array of nested objects is invalid",
"data": [
{"foo": {"bar" : {"baz" : true}}},
{"foo": {"bar" : {"baz" : true}}}
],
"valid": false
},
{
"description": "unique array of arrays is valid",
"data": [["foo"], ["bar"]],
"valid": true
},
{
"description": "non-unique array of arrays is invalid",
"data": [["foo"], ["foo"]],
"valid": false
},
{
"description": "non-unique array of more than two arrays is invalid",
"data": [["foo"], ["bar"], ["foo"]],
"valid": false
},
{
"description": "1 and true are unique",
"data": [1, true],
"valid": true
},
{
"description": "0 and false are unique",
"data": [0, false],
"valid": true
},
{
"description": "[1] and [true] are unique",
"data": [[1], [true]],
"valid": true
},
{
"description": "[0] and [false] are unique",
"data": [[0], [false]],
"valid": true
},
{
"description": "nested [1] and [true] are unique",
"data": [[[1], "foo"], [[true], "foo"]],
"valid": true
},
{
"description": "nested [0] and [false] are unique",
"data": [[[0], "foo"], [[false], "foo"]],
"valid": true
},
{
"description": "unique heterogeneous types are valid",
"data": [{}, [1], true, null, 1, "{}"],
"valid": true
},
{
"description": "non-unique heterogeneous types are invalid",
"data": [{}, [1], true, null, {}, 1],
"valid": false
},
{
"description": "different objects are unique",
"data": [{"a": 1, "b": 2}, {"a": 2, "b": 1}],
"valid": true
},
{
"description": "objects are non-unique despite key order",
"data": [{"a": 1, "b": 2}, {"b": 2, "a": 1}],
"valid": false
},
{
"description": "{\"a\": false} and {\"a\": 0} are unique",
"data": [{"a": false}, {"a": 0}],
"valid": true
},
{
"description": "{\"a\": true} and {\"a\": 1} are unique",
"data": [{"a": true}, {"a": 1}],
"valid": true
}
]
},
{
"description": "uniqueItems with an array of items",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [{"type": "boolean"}, {"type": "boolean"}],
"uniqueItems": true
},
"tests": [
{
"description": "[false, true] from items array is valid",
"data": [false, true],
"valid": true
},
{
"description": "[true, false] from items array is valid",
"data": [true, false],
"valid": true
},
{
"description": "[false, false] from items array is not valid",
"data": [false, false],
"valid": false
},
{
"description": "[true, true] from items array is not valid",
"data": [true, true],
"valid": false
},
{
"description": "unique array extended from [false, true] is valid",
"data": [false, true, "foo", "bar"],
"valid": true
},
{
"description": "unique array extended from [true, false] is valid",
"data": [true, false, "foo", "bar"],
"valid": true
},
{
"description": "non-unique array extended from [false, true] is not valid",
"data": [false, true, "foo", "foo"],
"valid": false
},
{
"description": "non-unique array extended from [true, false] is not valid",
"data": [true, false, "foo", "foo"],
"valid": false
}
]
},
{
"description": "uniqueItems with an array of items and additionalItems=false",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [{"type": "boolean"}, {"type": "boolean"}],
"uniqueItems": true,
"items": false
},
"tests": [
{
"description": "[false, true] from items array is valid",
"data": [false, true],
"valid": true
},
{
"description": "[true, false] from items array is valid",
"data": [true, false],
"valid": true
},
{
"description": "[false, false] from items array is not valid",
"data": [false, false],
"valid": false
},
{
"description": "[true, true] from items array is not valid",
"data": [true, true],
"valid": false
},
{
"description": "extra items are invalid even if unique",
"data": [false, true, null],
"valid": false
}
]
},
{
"description": "uniqueItems=false validation",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"uniqueItems": false
},
"tests": [
{
"description": "unique array of integers is valid",
"data": [1, 2],
"valid": true
},
{
"description": "non-unique array of integers is valid",
"data": [1, 1],
"valid": true
},
{
"description": "numbers are unique if mathematically unequal",
"data": [1.0, 1.00, 1],
"valid": true
},
{
"description": "false is not equal to zero",
"data": [0, false],
"valid": true
},
{
"description": "true is not equal to one",
"data": [1, true],
"valid": true
},
{
"description": "unique array of objects is valid",
"data": [{"foo": "bar"}, {"foo": "baz"}],
"valid": true
},
{
"description": "non-unique array of objects is valid",
"data": [{"foo": "bar"}, {"foo": "bar"}],
"valid": true
},
{
"description": "unique array of nested objects is valid",
"data": [
{"foo": {"bar" : {"baz" : true}}},
{"foo": {"bar" : {"baz" : false}}}
],
"valid": true
},
{
"description": "non-unique array of nested objects is valid",
"data": [
{"foo": {"bar" : {"baz" : true}}},
{"foo": {"bar" : {"baz" : true}}}
],
"valid": true
},
{
"description": "unique array of arrays is valid",
"data": [["foo"], ["bar"]],
"valid": true
},
{
"description": "non-unique array of arrays is valid",
"data": [["foo"], ["foo"]],
"valid": true
},
{
"description": "1 and true are unique",
"data": [1, true],
"valid": true
},
{
"description": "0 and false are unique",
"data": [0, false],
"valid": true
},
{
"description": "unique heterogeneous types are valid",
"data": [{}, [1], true, null, 1],
"valid": true
},
{
"description": "non-unique heterogeneous types are valid",
"data": [{}, [1], true, null, {}, 1],
"valid": true
}
]
},
{
"description": "uniqueItems=false with an array of items",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [{"type": "boolean"}, {"type": "boolean"}],
"uniqueItems": false
},
"tests": [
{
"description": "[false, true] from items array is valid",
"data": [false, true],
"valid": true
},
{
"description": "[true, false] from items array is valid",
"data": [true, false],
"valid": true
},
{
"description": "[false, false] from items array is valid",
"data": [false, false],
"valid": true
},
{
"description": "[true, true] from items array is valid",
"data": [true, true],
"valid": true
},
{
"description": "unique array extended from [false, true] is valid",
"data": [false, true, "foo", "bar"],
"valid": true
},
{
"description": "unique array extended from [true, false] is valid",
"data": [true, false, "foo", "bar"],
"valid": true
},
{
"description": "non-unique array extended from [false, true] is valid",
"data": [false, true, "foo", "foo"],
"valid": true
},
{
"description": "non-unique array extended from [true, false] is valid",
"data": [true, false, "foo", "foo"],
"valid": true
}
]
},
{
"description": "uniqueItems=false with an array of items and additionalItems=false",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"prefixItems": [{"type": "boolean"}, {"type": "boolean"}],
"uniqueItems": false,
"items": false
},
"tests": [
{
"description": "[false, true] from items array is valid",
"data": [false, true],
"valid": true
},
{
"description": "[true, false] from items array is valid",
"data": [true, false],
"valid": true
},
{
"description": "[false, false] from items array is valid",
"data": [false, false],
"valid": true
},
{
"description": "[true, true] from items array is valid",
"data": [true, true],
"valid": true
},
{
"description": "extra items are invalid even if unique",
"data": [false, true, null],
"valid": false
}
]
}
]
@@ -0,0 +1,57 @@
[
{
"description": "schema that uses custom metaschema with with no validation vocabulary",
"schema": {
"$id": "https://schema/using/no/validation",
"$schema": "http://localhost:1234/draft2020-12/metaschema-no-validation.json",
"properties": {
"badProperty": false,
"numberProperty": {
"minimum": 10
}
}
},
"tests": [
{
"description": "applicator vocabulary still works",
"data": {
"badProperty": "this property should not exist"
},
"valid": false
},
{
"description": "no validation: valid number",
"data": {
"numberProperty": 20
},
"valid": true
},
{
"description": "no validation: invalid number, but it still validates",
"data": {
"numberProperty": 1
},
"valid": true
}
]
},
{
"description": "ignore unrecognized optional vocabulary",
"schema": {
"$schema": "http://localhost:1234/draft2020-12/metaschema-optional-vocabulary.json",
"type": "number"
},
"tests": [
{
"description": "string value",
"data": "foobar",
"valid": false
},
{
"description": "number value",
"data": 20,
"valid": true
}
]
}
]
+258
View File
@@ -0,0 +1,258 @@
//! Integration tests for JSON Schema Test Suite compatibility
//!
//! This module tests that schemars-docgen can generate HTML documentation
//! for all schemas in the JSON-Schema-Test-Suite draft2020-12 examples
//! without crashing.
use rayon::prelude::*;
use serde::Deserialize;
use std::fs;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
use std::sync::Mutex;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
/// Represents a test suite from the JSON Schema Test Suite
#[derive(Debug, Deserialize)]
struct TestSuite {
description: String,
schema: serde_json::Value,
#[serde(default)]
#[allow(dead_code)]
tests: Vec<serde_json::Value>,
}
/// A schema test case with all context needed for parallel execution
#[derive(Debug)]
struct SchemaTestCase {
#[allow(dead_code)]
file_path: PathBuf,
relative_path: String,
index: usize,
description: String,
schema: serde_json::Value,
output_path: PathBuf,
}
/// Get the project root directory
fn project_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
}
/// Get the fixtures directory
fn fixtures_dir() -> PathBuf {
project_root().join("tests/fixtures/json-schema-test-suite/draft2020-12")
}
/// Get the test output directory
fn output_dir() -> PathBuf {
project_root().join("tests/outputs/json-schema-test-suite/draft2020-12")
}
/// Extract all schemas from a test suite file
fn extract_schemas(file_path: &Path) -> Vec<(String, serde_json::Value)> {
let content = fs::read_to_string(file_path).expect("Failed to read test file");
let suites: Vec<TestSuite> = serde_json::from_str(&content).expect("Failed to parse test file");
suites
.into_iter()
.map(|suite| (suite.description, suite.schema))
.collect()
}
/// Run the CLI against a schema and return success/failure
fn run_cli(schema: &serde_json::Value, output_path: &Path) -> Result<(), String> {
// Create a unique temporary file for the schema (use thread id to avoid conflicts)
let temp_dir = std::env::temp_dir();
let schema_file = temp_dir.join(format!(
"test_schema_{:?}_{}.json",
std::thread::current().id(),
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos()
));
fs::write(&schema_file, serde_json::to_string_pretty(schema).unwrap())
.map_err(|e| format!("Failed to write schema file: {}", e))?;
// Ensure output directory exists
if let Some(parent) = output_path.parent() {
fs::create_dir_all(parent)
.map_err(|e| format!("Failed to create output directory: {}", e))?;
}
// Run the CLI
let output = Command::new(env!("CARGO_BIN_EXE_schemars-docgen"))
.arg(&schema_file)
.arg("-o")
.arg(output_path)
.output()
.map_err(|e| format!("Failed to execute CLI: {}", e))?;
// Clean up temp file
let _ = fs::remove_file(&schema_file);
if output.status.success() {
Ok(())
} else {
let stderr = String::from_utf8_lossy(&output.stderr);
let stdout = String::from_utf8_lossy(&output.stdout);
Err(format!(
"CLI failed with status {:?}\nstderr: {}\nstdout: {}",
output.status.code(),
stderr,
stdout
))
}
}
/// Collect all JSON test files from a directory recursively
fn collect_test_files(dir: &Path) -> Vec<PathBuf> {
let mut files = Vec::new();
if dir.is_dir() {
for entry in fs::read_dir(dir).expect("Failed to read directory") {
let entry = entry.expect("Failed to read entry");
let path = entry.path();
if path.is_dir() {
files.extend(collect_test_files(&path));
} else if path.extension().map_or(false, |ext| ext == "json") {
files.push(path);
}
}
}
files.sort();
files
}
/// Convert a fixture file path to its corresponding output directory
fn fixture_to_output_dir(fixture_path: &Path) -> PathBuf {
let fixtures_base = fixtures_dir();
let relative = fixture_path
.strip_prefix(&fixtures_base)
.expect("Fixture path should be under fixtures dir");
// Remove .json extension and use as directory name
let stem = relative.with_extension("");
output_dir().join(stem)
}
/// Collect all test cases from all fixture files
fn collect_all_test_cases() -> Vec<SchemaTestCase> {
let fixtures = fixtures_dir();
let test_files = collect_test_files(&fixtures);
test_files
.into_iter()
.flat_map(|file_path| {
let schemas = extract_schemas(&file_path);
let output_base = fixture_to_output_dir(&file_path);
let relative_path = file_path
.strip_prefix(&fixtures)
.unwrap_or(&file_path)
.display()
.to_string();
schemas
.into_iter()
.enumerate()
.map(move |(idx, (description, schema))| SchemaTestCase {
file_path: file_path.clone(),
relative_path: relative_path.clone(),
index: idx,
description,
schema,
output_path: output_base.join(format!("{}.html", idx)),
})
})
.collect()
}
#[test]
fn test_all_json_schema_test_suite_schemas() {
let fixtures = fixtures_dir();
if !fixtures.exists() {
panic!(
"Fixtures directory not found: {:?}\n\
Please run: git clone --depth 1 https://github.com/json-schema-org/JSON-Schema-Test-Suite.git /tmp/json-schema-test-suite && \
mkdir -p fixtures/json-schema-test-suite && \
cp -r /tmp/json-schema-test-suite/tests/draft2020-12 fixtures/json-schema-test-suite/ && \
rm -rf /tmp/json-schema-test-suite",
fixtures
);
}
// Collect all test cases upfront
let test_cases = collect_all_test_cases();
let total_schemas = test_cases.len();
println!("Found {} schemas to test", total_schemas);
// Counters for progress
let passed = AtomicUsize::new(0);
let failed: Mutex<Vec<(String, usize, String, serde_json::Value, String)>> =
Mutex::new(Vec::new());
// Run tests in parallel
test_cases.par_iter().for_each(|test_case| {
match run_cli(&test_case.schema, &test_case.output_path) {
Ok(()) => {
passed.fetch_add(1, Ordering::Relaxed);
}
Err(e) => {
failed.lock().unwrap().push((
test_case.relative_path.clone(),
test_case.index,
test_case.description.clone(),
test_case.schema.clone(),
e,
));
}
}
});
let passed_count = passed.load(Ordering::Relaxed);
let failed_list = failed.into_inner().unwrap();
println!("\n=== Summary ===");
println!("Total schemas: {}", total_schemas);
println!("Passed: {}", passed_count);
println!("Failed: {}", failed_list.len());
if !failed_list.is_empty() {
println!("\n=== Failed Schemas ===");
for (relative_path, idx, desc, schema, error) in &failed_list {
println!("\n--- {}[{}]: {} ---", relative_path, idx, desc);
println!("Schema: {}", serde_json::to_string_pretty(schema).unwrap());
println!("Error: {}", error);
}
panic!(
"{} schemas failed to generate documentation",
failed_list.len()
);
}
}
/// Test a single schema file - useful for debugging specific failures
#[test]
#[ignore]
fn test_single_schema_file() {
let file_path = fixtures_dir().join("type.json");
let schemas = extract_schemas(&file_path);
let output_base = fixture_to_output_dir(&file_path);
for (idx, (description, schema)) in schemas.iter().enumerate() {
let output_path = output_base.join(format!("{}.html", idx));
println!("Testing: {} - {}", idx, description);
println!("Schema: {}", serde_json::to_string_pretty(schema).unwrap());
match run_cli(schema, &output_path) {
Ok(()) => println!(" PASS"),
Err(e) => panic!(" FAIL: {}", e),
}
}
}