Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/_includes/examples/doc_comments.schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "My Amazing Struct",
"description": "This struct shows off generating a schema with a custom title and description.",
"description": "This struct shows off generating a schema with\na custom title and description.",
"type": "object",
"required": [
"my_bool",
Expand Down Expand Up @@ -48,7 +48,7 @@
"additionalProperties": false
},
{
"description": "A struct-like enum variant which contains some floats",
"description": "A struct-like enum variant which contains\nsome floats",
"type": "object",
"required": [
"StructVariant"
Expand Down
5 changes: 5 additions & 0 deletions schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ bigdecimal04 = { version = "0.4", default-features = false, optional = true, pac
enumset = { version = "1.0", optional = true }
smol_str = { version = "0.1.17", optional = true }
semver = { version = "1.0.9", features = ["serde"], optional = true }
regex = { version = "1.12", optional = true }

[dev-dependencies]
pretty_assertions = "1.2.1"
Expand Down Expand Up @@ -123,6 +124,10 @@ required-features = ["enumset"]
name = "smol_str"
required-features = ["smol_str"]

[[test]]
name = "regex"
required-features = ["regex"]

[[test]]
name = "semver"
required-features = ["semver"]
Expand Down
4 changes: 2 additions & 2 deletions schemars/examples/doc_comments.schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "My Amazing Struct",
"description": "This struct shows off generating a schema with a custom title and description.",
"description": "This struct shows off generating a schema with\na custom title and description.",
"type": "object",
"required": [
"my_bool",
Expand Down Expand Up @@ -48,7 +48,7 @@
"additionalProperties": false
},
{
"description": "A struct-like enum variant which contains some floats",
"description": "A struct-like enum variant which contains\nsome floats",
"type": "object",
"required": [
"StructVariant"
Expand Down
2 changes: 2 additions & 0 deletions schemars/src/json_schema_impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ mod uuid08;
#[cfg(feature = "uuid1")]
mod uuid1;
mod wrapper;
#[cfg(feature = "regex")]
mod regex;
6 changes: 6 additions & 0 deletions schemars/src/json_schema_impls/regex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::r#gen::SchemaGenerator;
use crate::schema::*;
use crate::JsonSchema;
use regex::Regex;

forward_impl!(Regex => String);
4 changes: 2 additions & 2 deletions schemars/tests/expected/doc_comments_enum.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "This is the enum's title",
"description": "This is the enum's description.",
"description": "This is\nthe enum's description.",
"oneOf": [
{
"type": "string",
Expand Down Expand Up @@ -30,7 +30,7 @@
"properties": {
"my_nullable_string": {
"title": "A nullable string",
"description": "This field is a nullable string.\n\nThis is the second line!\n\nAnd this is the third!",
"description": "This field is a nullable string.\n\nThis\nis\nthe second\nline!\n\n\n\n\nAnd this is the third!",
"type": [
"string",
"null"
Expand Down
8 changes: 4 additions & 4 deletions schemars/tests/expected/schema-2019_09.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
]
},
"definitions": {
"description": "The `definitions` keyword.\n\nIn JSON Schema draft 2019-09 this was replaced by $defs, but in Schemars this is still serialized as `definitions` for backward-compatibility.\n\nSee [JSON Schema 8.2.5. Schema Re-Use With \"$defs\"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-8.2.5), and [JSON Schema (draft 07) 9. Schema Re-Use With \"definitions\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9).",
"description": "The `definitions` keyword.\n\nIn JSON Schema draft 2019-09 this was replaced by $defs, but in Schemars this is still\nserialized as `definitions` for backward-compatibility.\n\nSee [JSON Schema 8.2.5. Schema Re-Use With \"$defs\"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-8.2.5),\nand [JSON Schema (draft 07) 9. Schema Re-Use With \"definitions\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9).",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/Schema"
}
},
"type": {
"description": "The `type` keyword.\n\nSee [JSON Schema Validation 6.1.1. \"type\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.1) and [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).",
"description": "The `type` keyword.\n\nSee [JSON Schema Validation 6.1.1. \"type\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.1)\nand [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).",
"anyOf": [
{
"$ref": "#/definitions/SingleOrVec_for_InstanceType"
Expand Down Expand Up @@ -361,7 +361,7 @@
"description": "A JSON Schema.",
"anyOf": [
{
"description": "A trivial boolean JSON Schema.\n\nThe schema `true` matches everything (always passes validation), whereas the schema `false` matches nothing (always fails validation).",
"description": "A trivial boolean JSON Schema.\n\nThe schema `true` matches everything (always passes validation), whereas the schema `false`\nmatches nothing (always fails validation).",
"type": "boolean"
},
{
Expand All @@ -375,7 +375,7 @@
"type": "object",
"properties": {
"type": {
"description": "The `type` keyword.\n\nSee [JSON Schema Validation 6.1.1. \"type\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.1) and [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).",
"description": "The `type` keyword.\n\nSee [JSON Schema Validation 6.1.1. \"type\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.1)\nand [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).",
"anyOf": [
{
"$ref": "#/definitions/SingleOrVec_for_InstanceType"
Expand Down
8 changes: 4 additions & 4 deletions schemars/tests/expected/schema-openapi3.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"nullable": true
},
"definitions": {
"description": "The `definitions` keyword.\n\nIn JSON Schema draft 2019-09 this was replaced by $defs, but in Schemars this is still serialized as `definitions` for backward-compatibility.\n\nSee [JSON Schema 8.2.5. Schema Re-Use With \"$defs\"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-8.2.5), and [JSON Schema (draft 07) 9. Schema Re-Use With \"definitions\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9).",
"description": "The `definitions` keyword.\n\nIn JSON Schema draft 2019-09 this was replaced by $defs, but in Schemars this is still\nserialized as `definitions` for backward-compatibility.\n\nSee [JSON Schema 8.2.5. Schema Re-Use With \"$defs\"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-8.2.5),\nand [JSON Schema (draft 07) 9. Schema Re-Use With \"definitions\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9).",
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/Schema"
}
},
"type": {
"description": "The `type` keyword.\n\nSee [JSON Schema Validation 6.1.1. \"type\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.1) and [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).",
"description": "The `type` keyword.\n\nSee [JSON Schema Validation 6.1.1. \"type\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.1)\nand [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).",
"allOf": [
{
"$ref": "#/components/schemas/SingleOrVec_for_InstanceType"
Expand Down Expand Up @@ -297,7 +297,7 @@
"description": "A JSON Schema.",
"anyOf": [
{
"description": "A trivial boolean JSON Schema.\n\nThe schema `true` matches everything (always passes validation), whereas the schema `false` matches nothing (always fails validation).",
"description": "A trivial boolean JSON Schema.\n\nThe schema `true` matches everything (always passes validation), whereas the schema `false`\nmatches nothing (always fails validation).",
"type": "boolean"
},
{
Expand All @@ -315,7 +315,7 @@
"type": "object",
"properties": {
"type": {
"description": "The `type` keyword.\n\nSee [JSON Schema Validation 6.1.1. \"type\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.1) and [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).",
"description": "The `type` keyword.\n\nSee [JSON Schema Validation 6.1.1. \"type\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.1)\nand [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).",
"allOf": [
{
"$ref": "#/components/schemas/SingleOrVec_for_InstanceType"
Expand Down
8 changes: 4 additions & 4 deletions schemars/tests/expected/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
]
},
"definitions": {
"description": "The `definitions` keyword.\n\nIn JSON Schema draft 2019-09 this was replaced by $defs, but in Schemars this is still serialized as `definitions` for backward-compatibility.\n\nSee [JSON Schema 8.2.5. Schema Re-Use With \"$defs\"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-8.2.5), and [JSON Schema (draft 07) 9. Schema Re-Use With \"definitions\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9).",
"description": "The `definitions` keyword.\n\nIn JSON Schema draft 2019-09 this was replaced by $defs, but in Schemars this is still\nserialized as `definitions` for backward-compatibility.\n\nSee [JSON Schema 8.2.5. Schema Re-Use With \"$defs\"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-8.2.5),\nand [JSON Schema (draft 07) 9. Schema Re-Use With \"definitions\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9).",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/Schema"
}
},
"type": {
"description": "The `type` keyword.\n\nSee [JSON Schema Validation 6.1.1. \"type\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.1) and [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).",
"description": "The `type` keyword.\n\nSee [JSON Schema Validation 6.1.1. \"type\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.1)\nand [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).",
"anyOf": [
{
"$ref": "#/definitions/SingleOrVec_for_InstanceType"
Expand Down Expand Up @@ -361,7 +361,7 @@
"description": "A JSON Schema.",
"anyOf": [
{
"description": "A trivial boolean JSON Schema.\n\nThe schema `true` matches everything (always passes validation), whereas the schema `false` matches nothing (always fails validation).",
"description": "A trivial boolean JSON Schema.\n\nThe schema `true` matches everything (always passes validation), whereas the schema `false`\nmatches nothing (always fails validation).",
"type": "boolean"
},
{
Expand All @@ -379,7 +379,7 @@
"type": "object",
"properties": {
"type": {
"description": "The `type` keyword.\n\nSee [JSON Schema Validation 6.1.1. \"type\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.1) and [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).",
"description": "The `type` keyword.\n\nSee [JSON Schema Validation 6.1.1. \"type\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.1)\nand [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).",
"anyOf": [
{
"$ref": "#/definitions/SingleOrVec_for_InstanceType"
Expand Down
8 changes: 8 additions & 0 deletions schemars/tests/regex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod util;
use regex::Regex;
use util::*;

#[test]
fn regex() -> TestResult {
test_default_generated_schema::<Regex>("regex")
}
Loading