diff --git a/docs/_includes/examples/doc_comments.schema.json b/docs/_includes/examples/doc_comments.schema.json index 4997ac5..a3aa767 100644 --- a/docs/_includes/examples/doc_comments.schema.json +++ b/docs/_includes/examples/doc_comments.schema.json @@ -1,7 +1,7 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "My Amazing Struct", - "description": "This struct shows off generating a schema with\na custom title and description.", + "description": "This struct shows off generating a schema with\n a custom title and description.", "type": "object", "properties": { "my_bool": { @@ -48,7 +48,7 @@ ] }, { - "description": "A struct-like enum variant which contains\nsome floats", + "description": "A struct-like enum variant which contains\n some floats", "type": "object", "properties": { "StructVariant": { diff --git a/docs/_includes/examples/schemars_attrs.rs b/docs/_includes/examples/schemars_attrs.rs index 4ad2503..dc9e495 100644 --- a/docs/_includes/examples/schemars_attrs.rs +++ b/docs/_includes/examples/schemars_attrs.rs @@ -1,11 +1,11 @@ -use schemars::{schema_for, JsonSchema}; +use schemars::{schema_for, JsonSchema, Schema}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize, JsonSchema)] -#[schemars(rename_all = "camelCase", deny_unknown_fields)] +#[schemars(rename_all = "camelCase", deny_unknown_fields, extend("x-customProperty" = "example"))] pub struct MyStruct { #[serde(rename = "thisIsOverridden")] - #[schemars(rename = "myNumber", range(min = 1, max = 10))] + #[schemars(rename = "myNumber", range(min = 1, max = 10), transform = remove_format)] pub my_int: i32, pub my_bool: bool, #[schemars(default)] @@ -24,6 +24,12 @@ pub enum MyEnum { }, } +fn remove_format(schema: &mut Schema) { + if let Some(obj) = schema.as_object_mut() { + obj.remove("format"); + } +} + fn main() { let schema = schema_for!(MyStruct); println!("{}", serde_json::to_string_pretty(&schema).unwrap()); diff --git a/docs/_includes/examples/schemars_attrs.schema.json b/docs/_includes/examples/schemars_attrs.schema.json index ba96767..85efffd 100644 --- a/docs/_includes/examples/schemars_attrs.schema.json +++ b/docs/_includes/examples/schemars_attrs.schema.json @@ -19,7 +19,6 @@ }, "myNumber": { "type": "integer", - "format": "int32", "maximum": 10, "minimum": 1 }, @@ -37,6 +36,7 @@ "myBool", "myVecStr" ], + "x-customProperty": "example", "$defs": { "MyEnum": { "anyOf": [ diff --git a/schemars/examples/doc_comments.schema.json b/schemars/examples/doc_comments.schema.json index 4997ac5..a3aa767 100644 --- a/schemars/examples/doc_comments.schema.json +++ b/schemars/examples/doc_comments.schema.json @@ -1,7 +1,7 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "My Amazing Struct", - "description": "This struct shows off generating a schema with\na custom title and description.", + "description": "This struct shows off generating a schema with\n a custom title and description.", "type": "object", "properties": { "my_bool": { @@ -48,7 +48,7 @@ ] }, { - "description": "A struct-like enum variant which contains\nsome floats", + "description": "A struct-like enum variant which contains\n some floats", "type": "object", "properties": { "StructVariant": { diff --git a/schemars/examples/schemars_attrs.rs b/schemars/examples/schemars_attrs.rs index 4ad2503..dc9e495 100644 --- a/schemars/examples/schemars_attrs.rs +++ b/schemars/examples/schemars_attrs.rs @@ -1,11 +1,11 @@ -use schemars::{schema_for, JsonSchema}; +use schemars::{schema_for, JsonSchema, Schema}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize, JsonSchema)] -#[schemars(rename_all = "camelCase", deny_unknown_fields)] +#[schemars(rename_all = "camelCase", deny_unknown_fields, extend("x-customProperty" = "example"))] pub struct MyStruct { #[serde(rename = "thisIsOverridden")] - #[schemars(rename = "myNumber", range(min = 1, max = 10))] + #[schemars(rename = "myNumber", range(min = 1, max = 10), transform = remove_format)] pub my_int: i32, pub my_bool: bool, #[schemars(default)] @@ -24,6 +24,12 @@ pub enum MyEnum { }, } +fn remove_format(schema: &mut Schema) { + if let Some(obj) = schema.as_object_mut() { + obj.remove("format"); + } +} + fn main() { let schema = schema_for!(MyStruct); println!("{}", serde_json::to_string_pretty(&schema).unwrap()); diff --git a/schemars/examples/schemars_attrs.schema.json b/schemars/examples/schemars_attrs.schema.json index ba96767..85efffd 100644 --- a/schemars/examples/schemars_attrs.schema.json +++ b/schemars/examples/schemars_attrs.schema.json @@ -19,7 +19,6 @@ }, "myNumber": { "type": "integer", - "format": "int32", "maximum": 10, "minimum": 1 }, @@ -37,6 +36,7 @@ "myBool", "myVecStr" ], + "x-customProperty": "example", "$defs": { "MyEnum": { "anyOf": [