Support JSON Schema draft 2020-12 and use it by default (#294)

This commit is contained in:
Graham Esau 2024-05-19 20:49:45 +01:00 committed by GitHub
parent 95475ad1b4
commit 3aa0e7fa3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
88 changed files with 369 additions and 210 deletions

View file

@ -18,18 +18,18 @@ use std::{any::Any, collections::HashSet, fmt::Debug};
/// Settings to customize how Schemas are generated. /// Settings to customize how Schemas are generated.
/// ///
/// The default settings currently conform to [JSON Schema Draft 7](https://json-schema.org/specification-links.html#draft-7), but this is liable to change in a future version of Schemars if support for other JSON Schema versions is added. /// The default settings currently conform to [JSON Schema 2020-12](https://json-schema.org/specification-links#2020-12), but this is liable to change in a future version of Schemars if support for other JSON Schema versions is added.
/// If you require your generated schemas to conform to draft 7, consider using the [`draft07`](#method.draft07) method. /// If you rely on generated schemas conforming to draft 2020-12, consider using the [`SchemaSettings::draft2020_12()`] method.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[non_exhaustive] #[non_exhaustive]
pub struct SchemaSettings { pub struct SchemaSettings {
/// If `true`, schemas for [`Option<T>`](Option) will include a `nullable` property. /// If `true`, schemas for [`Option<T>`] will include a `nullable` property.
/// ///
/// This is not part of the JSON Schema spec, but is used in Swagger/OpenAPI schemas. /// This is not part of the JSON Schema spec, but is used in Swagger/OpenAPI schemas.
/// ///
/// Defaults to `false`. /// Defaults to `false`.
pub option_nullable: bool, pub option_nullable: bool,
/// If `true`, schemas for [`Option<T>`](Option) will have `null` added to their [`type`](../schema/struct.SchemaObject.html#structfield.instance_type). /// If `true`, schemas for [`Option<T>`] will have `null` added to their `type` property.
/// ///
/// Defaults to `true`. /// Defaults to `true`.
pub option_add_null_type: bool, pub option_add_null_type: bool,
@ -39,9 +39,9 @@ pub struct SchemaSettings {
pub definitions_path: String, pub definitions_path: String,
/// The URI of the meta-schema describing the structure of the generated schemas. /// The URI of the meta-schema describing the structure of the generated schemas.
/// ///
/// Defaults to `"http://json-schema.org/draft-07/schema#"`. /// Defaults to `"https://json-schema.org/draft/2020-12/schema"`.
pub meta_schema: Option<String>, pub meta_schema: Option<String>,
/// A list of visitors that get applied to all generated root schemas. /// A list of visitors that get applied to all generated schemas.
pub visitors: Vec<Box<dyn GenVisitor>>, pub visitors: Vec<Box<dyn GenVisitor>>,
/// Inline all subschemas instead of using references. /// Inline all subschemas instead of using references.
/// ///
@ -53,30 +53,42 @@ pub struct SchemaSettings {
impl Default for SchemaSettings { impl Default for SchemaSettings {
fn default() -> SchemaSettings { fn default() -> SchemaSettings {
SchemaSettings::draft07() SchemaSettings::draft2020_12()
} }
} }
impl SchemaSettings { impl SchemaSettings {
/// Creates `SchemaSettings` that conform to [JSON Schema Draft 7](https://json-schema.org/specification-links.html#draft-7). /// Creates `SchemaSettings` that conform to [JSON Schema Draft 7](https://json-schema.org/specification-links#draft-7).
pub fn draft07() -> SchemaSettings { pub fn draft07() -> SchemaSettings {
SchemaSettings { SchemaSettings {
option_nullable: false, option_nullable: false,
option_add_null_type: true, option_add_null_type: true,
definitions_path: "#/definitions/".to_owned(), definitions_path: "#/definitions/".to_owned(),
meta_schema: Some("http://json-schema.org/draft-07/schema#".to_owned()), meta_schema: Some("http://json-schema.org/draft-07/schema#".to_owned()),
visitors: vec![Box::new(RemoveRefSiblings)], visitors: vec![Box::new(RemoveRefSiblings), Box::new(ReplacePrefixItems)],
inline_subschemas: false, inline_subschemas: false,
} }
} }
/// Creates `SchemaSettings` that conform to [JSON Schema 2019-09](https://json-schema.org/specification-links.html#2019-09-formerly-known-as-draft-8). /// Creates `SchemaSettings` that conform to [JSON Schema 2019-09](https://json-schema.org/specification-links#draft-2019-09-(formerly-known-as-draft-8)).
pub fn draft2019_09() -> SchemaSettings { pub fn draft2019_09() -> SchemaSettings {
SchemaSettings { SchemaSettings {
option_nullable: false, option_nullable: false,
option_add_null_type: true, option_add_null_type: true,
definitions_path: "#/$defs/".to_owned(), definitions_path: "#/$defs/".to_owned(),
meta_schema: Some("https://json-schema.org/draft/2019-09/schema".to_owned()), meta_schema: Some("https://json-schema.org/draft/2019-09/schema".to_owned()),
visitors: vec![Box::new(ReplacePrefixItems)],
inline_subschemas: false,
}
}
/// Creates `SchemaSettings` that conform to [JSON Schema 2020-12](https://json-schema.org/specification-links#2020-12).
pub fn draft2020_12() -> SchemaSettings {
SchemaSettings {
option_nullable: false,
option_add_null_type: true,
definitions_path: "#/$defs/".to_owned(),
meta_schema: Some("https://json-schema.org/draft/2020-12/schema".to_owned()),
visitors: Vec::new(), visitors: Vec::new(),
inline_subschemas: false, inline_subschemas: false,
} }
@ -99,6 +111,7 @@ impl SchemaSettings {
}), }),
Box::new(SetSingleExample), Box::new(SetSingleExample),
Box::new(ReplaceConstValue), Box::new(ReplaceConstValue),
Box::new(ReplacePrefixItems),
], ],
inline_subschemas: false, inline_subschemas: false,
} }

View file

@ -25,7 +25,7 @@ macro_rules! tuple_impls {
fn json_schema(gen: &mut SchemaGenerator) -> Schema { fn json_schema(gen: &mut SchemaGenerator) -> Schema {
json_schema!({ json_schema!({
"type": "array", "type": "array",
"items": [ "prefixItems": [
$(gen.subschema_for::<$name>()),+ $(gen.subschema_for::<$name>()),+
], ],
"minItems": $len, "minItems": $len,

View file

@ -378,7 +378,7 @@ impl serde::ser::SerializeTuple for SerializeTuple<'_> {
let len = self.items.len(); let len = self.items.len();
let mut schema = json_schema!({ let mut schema = json_schema!({
"type": "array", "type": "array",
"items": self.items, "prefixItems": self.items,
"maxItems": len, "maxItems": len,
"minItems": len, "minItems": len,
}); });

View file

@ -50,15 +50,15 @@ pub fn visit_schema<V: Visitor + ?Sized>(v: &mut V, schema: &mut Schema) {
| "if" | "if"
| "then" | "then"
| "else" | "else"
| "additionalItems"
| "contains" | "contains"
| "additionalProperties" | "additionalProperties"
| "propertyNames" => { | "propertyNames"
| "items" => {
if let Ok(subschema) = value.try_into() { if let Ok(subschema) = value.try_into() {
v.visit_schema(subschema) v.visit_schema(subschema)
} }
} }
"allOf" | "anyOf" | "oneOf" => { "allOf" | "anyOf" | "oneOf" | "prefixItems" => {
if let Some(array) = value.as_array_mut() { if let Some(array) = value.as_array_mut() {
for value in array { for value in array {
if let Ok(subschema) = value.try_into() { if let Ok(subschema) = value.try_into() {
@ -67,17 +67,6 @@ pub fn visit_schema<V: Visitor + ?Sized>(v: &mut V, schema: &mut Schema) {
} }
} }
} }
"items" => {
if let Some(array) = value.as_array_mut() {
for value in array {
if let Ok(subschema) = value.try_into() {
v.visit_schema(subschema)
}
}
} else if let Ok(subschema) = value.try_into() {
v.visit_schema(subschema)
}
}
"properties" | "patternProperties" => { "properties" | "patternProperties" => {
if let Some(obj) = value.as_object_mut() { if let Some(obj) = value.as_object_mut() {
for value in obj.values_mut() { for value in obj.values_mut() {
@ -126,7 +115,7 @@ impl Visitor for ReplaceBoolSchemas {
/// This visitor will restructure JSON Schema objects so that the `$ref` property will never appear alongside any other properties. /// This visitor will restructure JSON Schema objects so that the `$ref` property will never appear alongside any other properties.
/// ///
/// This is useful for dialects of JSON Schema (e.g. Draft 7) that do not support other properties alongside `$ref`. /// This is useful for versions of JSON Schema (e.g. Draft 7) that do not support other properties alongside `$ref`.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct RemoveRefSiblings; pub struct RemoveRefSiblings;
@ -187,3 +176,27 @@ impl Visitor for ReplaceConstValue {
} }
} }
} }
/// This visitor will rename the `prefixItems` schema property to `items`.
///
/// If the schema contains both `prefixItems` and `items`, then this additionally renames `items` to `additionalItems`.
///
/// This is useful for versions of JSON Schema (e.g. Draft 7) that do not support the `prefixItems` property.
#[derive(Debug, Clone)]
pub struct ReplacePrefixItems;
impl Visitor for ReplacePrefixItems {
fn visit_schema(&mut self, schema: &mut Schema) {
visit_schema(self, schema);
if let Some(obj) = schema.as_object_mut() {
if let Some(prefix_items) = obj.remove("prefixItems") {
let previous_items = obj.insert("items".to_owned(), prefix_items);
if let Some(previous_items) = previous_items {
obj.insert("additionalItems".to_owned(), previous_items);
}
}
}
}
}

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Array_up_to_size_16_of_int32", "title": "Array_up_to_size_16_of_int32",
"type": "array", "type": "array",
"items": { "items": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "string", "title": "string",
"type": "string" "type": "string"
} }

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Decimal", "title": "Decimal",
"type": "string", "type": "string",
"pattern": "^-?[0-9]+(\\.[0-9]+)?$" "pattern": "^-?[0-9]+(\\.[0-9]+)?$"

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyContainer", "title": "MyContainer",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,8 +1,8 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Tuple_of_Array_of_uint8_and_Array_of_uint8", "title": "Tuple_of_Array_of_uint8_and_Array_of_uint8",
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "array", "type": "array",
"items": { "items": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "ChronoTypes", "title": "ChronoTypes",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Struct", "title": "Struct",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyStruct", "title": "MyStruct",
"type": "object", "type": "object",
"properties": { "properties": {
@ -13,21 +13,17 @@
"default": false "default": false
}, },
"my_struct2": { "my_struct2": {
"default": "i:0 b:false", "$ref": "#/$defs/MyStruct2",
"allOf": [ "default": "i:0 b:false"
{
"$ref": "#/definitions/MyStruct2"
}
]
}, },
"my_struct2_default_skipped": { "my_struct2_default_skipped": {
"$ref": "#/definitions/MyStruct2" "$ref": "#/$defs/MyStruct2"
}, },
"not_serialize": { "not_serialize": {
"$ref": "#/definitions/NotSerialize" "$ref": "#/$defs/NotSerialize"
} }
}, },
"definitions": { "$defs": {
"MyStruct2": { "MyStruct2": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "DeprecatedEnum", "title": "DeprecatedEnum",
"oneOf": [ "oneOf": [
{ {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "DeprecatedStruct", "title": "DeprecatedStruct",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "This is the enum's title", "title": "This is the enum's title",
"description": "This is the enum's description.", "description": "This is the enum's description.",
"oneOf": [ "oneOf": [

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "OverrideDocs struct", "title": "OverrideDocs struct",
"description": "New description", "description": "New description",
"type": "object", "type": "object",

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "This is the struct's title", "title": "This is the struct's title",
"description": "This is the struct's description.", "description": "This is the struct's description.",
"type": "object", "type": "object",
@ -14,11 +14,7 @@
}, },
"my_unit": { "my_unit": {
"description": "A unit struct instance", "description": "A unit struct instance",
"allOf": [ "$ref": "#/$defs/MyUnitStruct"
{
"$ref": "#/definitions/MyUnitStruct"
}
]
} }
}, },
"required": [ "required": [
@ -26,7 +22,7 @@
"my_undocumented_bool", "my_undocumented_bool",
"my_unit" "my_unit"
], ],
"definitions": { "$defs": {
"MyUnitStruct": { "MyUnitStruct": {
"title": "A Unit", "title": "A Unit",
"type": "null" "type": "null"

View file

@ -1,20 +1,20 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyStruct", "title": "MyStruct",
"type": "object", "type": "object",
"properties": { "properties": {
"duration": { "duration": {
"$ref": "#/definitions/Duration" "$ref": "#/$defs/Duration"
}, },
"time": { "time": {
"$ref": "#/definitions/SystemTime" "$ref": "#/$defs/SystemTime"
} }
}, },
"required": [ "required": [
"duration", "duration",
"time" "time"
], ],
"definitions": { "$defs": {
"Duration": { "Duration": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Either_int32_or_Either_boolean_or_null", "title": "Either_int32_or_Either_boolean_or_null",
"anyOf": [ "anyOf": [
{ {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Adjacent", "title": "Adjacent",
"oneOf": [ "oneOf": [
{ {
@ -49,7 +49,7 @@
] ]
}, },
"c": { "c": {
"$ref": "#/definitions/UnitStruct" "$ref": "#/$defs/UnitStruct"
} }
}, },
"required": [ "required": [
@ -68,7 +68,7 @@
] ]
}, },
"c": { "c": {
"$ref": "#/definitions/Struct" "$ref": "#/$defs/Struct"
} }
}, },
"required": [ "required": [
@ -121,7 +121,7 @@
}, },
"c": { "c": {
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "integer", "type": "integer",
"format": "int32" "format": "int32"
@ -176,7 +176,7 @@
"additionalProperties": false "additionalProperties": false
} }
], ],
"definitions": { "$defs": {
"UnitStruct": { "UnitStruct": {
"type": "null" "type": "null"
}, },

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Adjacent", "title": "Adjacent",
"oneOf": [ "oneOf": [
{ {
@ -47,7 +47,7 @@
] ]
}, },
"c": { "c": {
"$ref": "#/definitions/UnitStruct" "$ref": "#/$defs/UnitStruct"
} }
}, },
"required": [ "required": [
@ -65,7 +65,7 @@
] ]
}, },
"c": { "c": {
"$ref": "#/definitions/Struct" "$ref": "#/$defs/Struct"
} }
}, },
"required": [ "required": [
@ -115,7 +115,7 @@
}, },
"c": { "c": {
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "integer", "type": "integer",
"format": "int32" "format": "int32"
@ -167,7 +167,7 @@
] ]
} }
], ],
"definitions": { "$defs": {
"UnitStruct": { "UnitStruct": {
"type": "null" "type": "null"
}, },

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "External", "title": "External",
"oneOf": [ "oneOf": [
{ {
@ -28,7 +28,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"unitStructNewType": { "unitStructNewType": {
"$ref": "#/definitions/UnitStruct" "$ref": "#/$defs/UnitStruct"
} }
}, },
"required": [ "required": [
@ -40,7 +40,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"structNewType": { "structNewType": {
"$ref": "#/definitions/Struct" "$ref": "#/$defs/Struct"
} }
}, },
"required": [ "required": [
@ -79,7 +79,7 @@
"properties": { "properties": {
"tuple": { "tuple": {
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "integer", "type": "integer",
"format": "int32" "format": "int32"
@ -111,7 +111,7 @@
"additionalProperties": false "additionalProperties": false
} }
], ],
"definitions": { "$defs": {
"UnitStruct": { "UnitStruct": {
"type": "null" "type": "null"
}, },

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "External", "title": "External",
"oneOf": [ "oneOf": [
{ {
@ -28,7 +28,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"unitStructNewType": { "unitStructNewType": {
"$ref": "#/definitions/UnitStruct" "$ref": "#/$defs/UnitStruct"
} }
}, },
"required": [ "required": [
@ -40,7 +40,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"structNewType": { "structNewType": {
"$ref": "#/definitions/Struct" "$ref": "#/$defs/Struct"
} }
}, },
"required": [ "required": [
@ -78,7 +78,7 @@
"properties": { "properties": {
"tuple": { "tuple": {
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "integer", "type": "integer",
"format": "int32" "format": "int32"
@ -110,7 +110,7 @@
"additionalProperties": false "additionalProperties": false
} }
], ],
"definitions": { "$defs": {
"UnitStruct": { "UnitStruct": {
"type": "null" "type": "null"
}, },

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Internal", "title": "Internal",
"oneOf": [ "oneOf": [
{ {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Internal", "title": "Internal",
"oneOf": [ "oneOf": [
{ {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Renamed", "title": "Renamed",
"description": "Description from comment", "description": "Description from comment",
"type": "integer", "type": "integer",

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Enum", "title": "Enum",
"type": "integer", "type": "integer",
"enum": [ "enum": [

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "SimpleInternal", "title": "SimpleInternal",
"oneOf": [ "oneOf": [
{ {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "SimpleInternal", "title": "SimpleInternal",
"oneOf": [ "oneOf": [
{ {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "SoundOfMusic", "title": "SoundOfMusic",
"oneOf": [ "oneOf": [
{ {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Untagged", "title": "Untagged",
"anyOf": [ "anyOf": [
{ {
@ -12,10 +12,10 @@
} }
}, },
{ {
"$ref": "#/definitions/UnitStruct" "$ref": "#/$defs/UnitStruct"
}, },
{ {
"$ref": "#/definitions/Struct" "$ref": "#/$defs/Struct"
}, },
{ {
"type": "object", "type": "object",
@ -36,7 +36,7 @@
}, },
{ {
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "integer", "type": "integer",
"format": "int32" "format": "int32"
@ -53,7 +53,7 @@
"format": "int32" "format": "int32"
} }
], ],
"definitions": { "$defs": {
"UnitStruct": { "UnitStruct": {
"type": "null" "type": "null"
}, },

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Untagged", "title": "Untagged",
"anyOf": [ "anyOf": [
{ {
@ -12,10 +12,10 @@
} }
}, },
{ {
"$ref": "#/definitions/UnitStruct" "$ref": "#/$defs/UnitStruct"
}, },
{ {
"$ref": "#/definitions/Struct" "$ref": "#/$defs/Struct"
}, },
{ {
"type": "object", "type": "object",
@ -35,7 +35,7 @@
}, },
{ {
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "integer", "type": "integer",
"format": "int32" "format": "int32"
@ -52,7 +52,7 @@
"format": "int32" "format": "int32"
} }
], ],
"definitions": { "$defs": {
"UnitStruct": { "UnitStruct": {
"type": "null" "type": "null"
}, },

View file

@ -1,12 +1,12 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Set_of_Foo", "title": "Set_of_Foo",
"type": "array", "type": "array",
"uniqueItems": true, "uniqueItems": true,
"items": { "items": {
"$ref": "#/definitions/Foo" "$ref": "#/$defs/Foo"
}, },
"definitions": { "$defs": {
"Foo": { "Foo": {
"type": "string", "type": "string",
"enum": [ "enum": [

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Struct", "title": "Struct",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Flat", "title": "Flat",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object", "type": "object",
"properties": { "properties": {
"zero": { "zero": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "IndexMapTypes", "title": "IndexMapTypes",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,12 +1,12 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "RecursiveOuter", "title": "RecursiveOuter",
"type": "object", "type": "object",
"properties": { "properties": {
"direct": { "direct": {
"anyOf": [ "anyOf": [
{ {
"$ref": "#/definitions/RecursiveOuter" "$ref": "#/$defs/RecursiveOuter"
}, },
{ {
"type": "null" "type": "null"
@ -20,7 +20,7 @@
], ],
"properties": { "properties": {
"recursive": { "recursive": {
"$ref": "#/definitions/RecursiveOuter" "$ref": "#/$defs/RecursiveOuter"
} }
}, },
"required": [ "required": [
@ -28,14 +28,14 @@
] ]
} }
}, },
"definitions": { "$defs": {
"RecursiveOuter": { "RecursiveOuter": {
"type": "object", "type": "object",
"properties": { "properties": {
"direct": { "direct": {
"anyOf": [ "anyOf": [
{ {
"$ref": "#/definitions/RecursiveOuter" "$ref": "#/$defs/RecursiveOuter"
}, },
{ {
"type": "null" "type": "null"
@ -49,7 +49,7 @@
], ],
"properties": { "properties": {
"recursive": { "recursive": {
"$ref": "#/definitions/RecursiveOuter" "$ref": "#/$defs/RecursiveOuter"
} }
}, },
"required": [ "required": [

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyJob", "title": "MyJob",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,12 +1,12 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "OuterEnum", "title": "OuterEnum",
"oneOf": [ "oneOf": [
{ {
"type": "object", "type": "object",
"properties": { "properties": {
"InnerStruct": { "InnerStruct": {
"$ref": "#/definitions/InnerStruct" "$ref": "#/$defs/InnerStruct"
} }
}, },
"required": [ "required": [
@ -15,7 +15,7 @@
"additionalProperties": false "additionalProperties": false
} }
], ],
"definitions": { "$defs": {
"InnerStruct": { "InnerStruct": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "A", "title": "A",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "NoVariants", "title": "NoVariants",
"type": "string", "type": "string",
"enum": [] "enum": []

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyStruct", "title": "MyStruct",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,20 +1,20 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "OsStrings", "title": "OsStrings",
"type": "object", "type": "object",
"properties": { "properties": {
"owned": { "owned": {
"$ref": "#/definitions/OsString" "$ref": "#/$defs/OsString"
}, },
"borrowed": { "borrowed": {
"$ref": "#/definitions/OsString" "$ref": "#/$defs/OsString"
} }
}, },
"required": [ "required": [
"owned", "owned",
"borrowed" "borrowed"
], ],
"definitions": { "$defs": {
"OsString": { "OsString": {
"oneOf": [ "oneOf": [
{ {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyStruct", "title": "MyStruct",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,16 +1,16 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyStruct", "title": "MyStruct",
"type": "object", "type": "object",
"properties": { "properties": {
"range": { "range": {
"$ref": "#/definitions/Range_of_uint" "$ref": "#/$defs/Range_of_uint"
}, },
"inclusive": { "inclusive": {
"$ref": "#/definitions/Range_of_double" "$ref": "#/$defs/Range_of_double"
}, },
"bound": { "bound": {
"$ref": "#/definitions/Bound_of_string" "$ref": "#/$defs/Bound_of_string"
} }
}, },
"required": [ "required": [
@ -18,7 +18,7 @@
"inclusive", "inclusive",
"bound" "bound"
], ],
"definitions": { "$defs": {
"Range_of_uint": { "Range_of_uint": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Process", "title": "Process",
"type": "object", "type": "object",
"properties": { "properties": {
@ -7,33 +7,25 @@
"type": "string" "type": "string"
}, },
"wall_time": { "wall_time": {
"$ref": "#/definitions/Duration" "$ref": "#/$defs/Duration"
}, },
"user_cpu_time": { "user_cpu_time": {
"$ref": "#/$defs/Duration",
"default": { "default": {
"secs": 0, "secs": 0,
"nanos": 0 "nanos": 0
},
"allOf": [
{
"$ref": "#/definitions/Duration"
} }
]
}, },
"system_cpu_time": { "system_cpu_time": {
"default": "0.000000000s", "$ref": "#/$defs/Duration",
"allOf": [ "default": "0.000000000s"
{
"$ref": "#/definitions/Duration"
}
]
} }
}, },
"required": [ "required": [
"command_line", "command_line",
"wall_time" "wall_time"
], ],
"definitions": { "$defs": {
"Duration": { "Duration": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,16 +1,16 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyStruct_for_int32", "title": "MyStruct_for_int32",
"type": "object", "type": "object",
"properties": { "properties": {
"byte_or_bool2": { "byte_or_bool2": {
"$ref": "#/definitions/Or_for_uint8_and_boolean" "$ref": "#/$defs/Or_for_uint8_and_boolean"
}, },
"unit_or_t2": { "unit_or_t2": {
"$ref": "#/definitions/Or_for_null_and_int32" "$ref": "#/$defs/Or_for_null_and_int32"
}, },
"s": { "s": {
"$ref": "#/definitions/Str" "$ref": "#/$defs/Str"
}, },
"fake_map": { "fake_map": {
"type": "object", "type": "object",
@ -29,7 +29,7 @@
"s", "s",
"fake_map" "fake_map"
], ],
"definitions": { "$defs": {
"Or_for_uint8_and_boolean": { "Or_for_uint8_and_boolean": {
"anyOf": [ "anyOf": [
{ {

View file

@ -1,27 +1,27 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Container", "title": "Container",
"type": "object", "type": "object",
"properties": { "properties": {
"result1": { "result1": {
"$ref": "#/definitions/Result_of_MyStruct_or_Array_of_string" "$ref": "#/$defs/Result_of_MyStruct_or_Array_of_string"
}, },
"result2": { "result2": {
"$ref": "#/definitions/Result_of_boolean_or_null" "$ref": "#/$defs/Result_of_boolean_or_null"
} }
}, },
"required": [ "required": [
"result1", "result1",
"result2" "result2"
], ],
"definitions": { "$defs": {
"Result_of_MyStruct_or_Array_of_string": { "Result_of_MyStruct_or_Array_of_string": {
"oneOf": [ "oneOf": [
{ {
"type": "object", "type": "object",
"properties": { "properties": {
"Ok": { "Ok": {
"$ref": "#/definitions/MyStruct" "$ref": "#/$defs/MyStruct"
} }
}, },
"required": [ "required": [

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Decimal", "title": "Decimal",
"type": "string", "type": "string",
"pattern": "^-?[0-9]+(\\.[0-9]+)?$" "pattern": "^-?[0-9]+(\\.[0-9]+)?$"

View file

@ -1,20 +1,20 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Config2", "title": "Config2",
"type": "object", "type": "object",
"properties": { "properties": {
"a_cfg": { "a_cfg": {
"$ref": "#/definitions/Config" "$ref": "#/$defs/Config"
}, },
"b_cfg": { "b_cfg": {
"$ref": "#/definitions/Config2" "$ref": "#/$defs/Config2"
} }
}, },
"required": [ "required": [
"a_cfg", "a_cfg",
"b_cfg" "b_cfg"
], ],
"definitions": { "$defs": {
"Config": { "Config": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "const-generics-z-42", "title": "const-generics-z-42",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "a-new-name-Array_of_string-int32-int32", "title": "a-new-name-Array_of_string-int32-int32",
"type": "object", "type": "object",
"properties": { "properties": {
@ -20,7 +20,7 @@
} }
}, },
"inner": { "inner": {
"$ref": "#/definitions/another-new-name" "$ref": "#/$defs/another-new-name"
} }
}, },
"required": [ "required": [
@ -30,7 +30,7 @@
"w", "w",
"inner" "inner"
], ],
"definitions": { "$defs": {
"another-new-name": { "another-new-name": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyStruct_for_int32_and_null_and_boolean_and_Array_of_string", "title": "MyStruct_for_int32_and_null_and_boolean_and_Array_of_string",
"type": "object", "type": "object",
"properties": { "properties": {
@ -20,7 +20,7 @@
} }
}, },
"inner": { "inner": {
"$ref": "#/definitions/MySimpleStruct" "$ref": "#/$defs/MySimpleStruct"
} }
}, },
"required": [ "required": [
@ -30,7 +30,7 @@
"w", "w",
"inner" "inner"
], ],
"definitions": { "$defs": {
"MySimpleStruct": { "MySimpleStruct": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,10 +1,10 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MixedGenericStruct_for_MyStruct_for_int32_and_null_and_boolean_and_Array_of_string_and_42_and_z", "title": "MixedGenericStruct_for_MyStruct_for_int32_and_null_and_boolean_and_Array_of_string_and_42_and_z",
"type": "object", "type": "object",
"properties": { "properties": {
"generic": { "generic": {
"$ref": "#/definitions/MyStruct_for_int32_and_null_and_boolean_and_Array_of_string" "$ref": "#/$defs/MyStruct_for_int32_and_null_and_boolean_and_Array_of_string"
}, },
"foo": { "foo": {
"type": "integer", "type": "integer",
@ -15,7 +15,7 @@
"generic", "generic",
"foo" "foo"
], ],
"definitions": { "$defs": {
"MyStruct_for_int32_and_null_and_boolean_and_Array_of_string": { "MyStruct_for_int32_and_null_and_boolean_and_Array_of_string": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -36,7 +36,7 @@
} }
}, },
"inner": { "inner": {
"$ref": "#/definitions/MySimpleStruct" "$ref": "#/$defs/MySimpleStruct"
} }
}, },
"required": [ "required": [

View file

@ -25,12 +25,32 @@
"type": "null" "type": "null"
} }
] ]
},
"tuples": {
"type": "array",
"items": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint8",
"minimum": 0
},
{
"type": "integer",
"format": "int64"
}
],
"minItems": 2,
"maxItems": 2
}
} }
}, },
"required": [ "required": [
"int", "int",
"values", "values",
"value" "value",
"tuples"
], ],
"$defs": { "$defs": {
"Inner": { "Inner": {

View file

@ -0,0 +1,83 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Outer",
"type": "object",
"properties": {
"int": {
"type": "integer",
"format": "int32",
"examples": [
8,
null
]
},
"values": {
"type": "object",
"additionalProperties": true
},
"value": true,
"inner": {
"anyOf": [
{
"$ref": "#/$defs/Inner"
},
{
"type": "null"
}
]
},
"tuples": {
"type": "array",
"items": {
"type": "array",
"prefixItems": [
{
"type": "integer",
"format": "uint8",
"minimum": 0
},
{
"type": "integer",
"format": "int64"
}
],
"minItems": 2,
"maxItems": 2
}
}
},
"required": [
"int",
"values",
"value",
"tuples"
],
"$defs": {
"Inner": {
"oneOf": [
{
"type": "string",
"enum": [
"UndocumentedUnit1",
"UndocumentedUnit2"
]
},
{
"description": "This is a documented unit variant",
"type": "string",
"const": "DocumentedUnit"
},
{
"type": "object",
"properties": {
"ValueNewType": true
},
"required": [
"ValueNewType"
],
"additionalProperties": false
}
]
}
}
}

View file

@ -20,12 +20,32 @@
"$ref": "#/components/schemas/Inner" "$ref": "#/components/schemas/Inner"
} }
] ]
},
"tuples": {
"type": "array",
"items": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint8",
"minimum": 0
},
{
"type": "integer",
"format": "int64"
}
],
"minItems": 2,
"maxItems": 2
}
} }
}, },
"required": [ "required": [
"int", "int",
"values", "values",
"value" "value",
"tuples"
], ],
"components": { "components": {
"schemas": { "schemas": {

View file

@ -25,12 +25,32 @@
"type": "null" "type": "null"
} }
] ]
},
"tuples": {
"type": "array",
"items": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint8",
"minimum": 0
},
{
"type": "integer",
"format": "int64"
}
],
"minItems": 2,
"maxItems": 2
}
} }
}, },
"required": [ "required": [
"int", "int",
"values", "values",
"value" "value",
"tuples"
], ],
"definitions": { "definitions": {
"Inner": { "Inner": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Adjacent", "title": "Adjacent",
"oneOf": [ "oneOf": [
{ {
@ -57,7 +57,7 @@
}, },
"c": { "c": {
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "boolean" "type": "boolean"
}, },

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "External", "title": "External",
"oneOf": [ "oneOf": [
{ {
@ -39,7 +39,7 @@
"properties": { "properties": {
"tuple": { "tuple": {
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "boolean" "type": "boolean"
}, },

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Internal", "title": "Internal",
"oneOf": [ "oneOf": [
{ {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Untagged", "title": "Untagged",
"anyOf": [ "anyOf": [
{ {
@ -18,7 +18,7 @@
}, },
{ {
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "boolean" "type": "boolean"
}, },

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Newtype", "title": "Newtype",
"type": "boolean" "type": "boolean"
} }

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Struct", "title": "Struct",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "schema_fn", "title": "schema_fn",
"type": "boolean" "type": "boolean"
} }

View file

@ -1,8 +1,8 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Tuple", "title": "Tuple",
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "boolean" "type": "boolean"
}, },

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "SemverTypes", "title": "SemverTypes",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyEnum", "title": "MyEnum",
"oneOf": [ "oneOf": [
{ {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyStruct", "title": "MyStruct",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,8 +1,8 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "TupleStruct", "title": "TupleStruct",
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "number", "type": "number",
"format": "float" "format": "float"

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Array_of_string", "title": "Array_of_string",
"type": "array", "type": "array",
"items": { "items": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "string", "title": "string",
"type": "string" "type": "string"
} }

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Newtype", "title": "Newtype",
"type": "integer", "type": "integer",
"format": "int32" "format": "int32"

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Struct", "title": "Struct",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Struct", "title": "Struct",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,8 +1,8 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Tuple", "title": "Tuple",
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "integer", "type": "integer",
"format": "int32" "format": "int32"

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Unit", "title": "Unit",
"type": "null" "type": "null"
} }

View file

@ -1,12 +1,12 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "OuterStruct", "title": "OuterStruct",
"type": "object", "type": "object",
"properties": { "properties": {
"inner": { "inner": {
"anyOf": [ "anyOf": [
{ {
"$ref": "#/definitions/InnerStruct" "$ref": "#/$defs/InnerStruct"
}, },
{ {
"type": "null" "type": "null"
@ -14,10 +14,10 @@
] ]
} }
}, },
"definitions": { "$defs": {
"InnerStruct": { "InnerStruct": {
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "string" "type": "string"
}, },

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "UrlTypes", "title": "UrlTypes",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Uuid", "title": "Uuid",
"type": "string", "type": "string",
"format": "uuid" "format": "uuid"

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Struct", "title": "Struct",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Struct", "title": "Struct",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "NewType", "title": "NewType",
"type": "integer", "type": "integer",
"format": "uint8", "format": "uint8",

View file

@ -1,5 +1,5 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Struct2", "title": "Struct2",
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,8 +1,8 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Tuple", "title": "Tuple",
"type": "array", "type": "array",
"items": [ "prefixItems": [
{ {
"type": "integer", "type": "integer",
"format": "uint8", "format": "uint8",

View file

@ -12,6 +12,7 @@ pub struct Outer {
pub values: BTreeMap<&'static str, Value>, pub values: BTreeMap<&'static str, Value>,
pub value: Value, pub value: Value,
pub inner: Option<Inner>, pub inner: Option<Inner>,
pub tuples: Vec<(u8, i64)>,
} }
#[derive(JsonSchema)] #[derive(JsonSchema)]
@ -39,6 +40,11 @@ fn schema_matches_2019_09() -> TestResult {
test_generated_schema::<Outer>("schema_settings-2019_09", SchemaSettings::draft2019_09()) test_generated_schema::<Outer>("schema_settings-2019_09", SchemaSettings::draft2019_09())
} }
#[test]
fn schema_matches_2020_12() -> TestResult {
test_generated_schema::<Outer>("schema_settings-2020_12", SchemaSettings::draft2020_12())
}
#[test] #[test]
fn schema_matches_openapi3() -> TestResult { fn schema_matches_openapi3() -> TestResult {
test_generated_schema::<Outer>("schema_settings-openapi3", SchemaSettings::openapi3()) test_generated_schema::<Outer>("schema_settings-openapi3", SchemaSettings::openapi3())

View file

@ -422,7 +422,7 @@ fn expr_for_tuple_struct(fields: &[Field]) -> TokenStream {
quote! { quote! {
schemars::json_schema!({ schemars::json_schema!({
"type": "array", "type": "array",
"items": [#((#fields)),*], "prefixItems": [#((#fields)),*],
"minItems": #len, "minItems": #len,
"maxItems": #len, "maxItems": #len,
}) })