diff --git a/schemars/tests/docs.rs b/schemars/tests/integration/docs.rs similarity index 81% rename from schemars/tests/docs.rs rename to schemars/tests/integration/docs.rs index 7086c693..4ca11c76 100644 --- a/schemars/tests/docs.rs +++ b/schemars/tests/integration/docs.rs @@ -1,6 +1,4 @@ -mod util; -use schemars::JsonSchema; -use util::*; +use crate::prelude::*; #[allow(dead_code)] #[derive(JsonSchema)] @@ -24,6 +22,11 @@ struct MyStruct { #[derive(JsonSchema)] struct MyUnitStruct; +#[test] +fn doc_comments_struct() { + test!(MyStruct).assert_snapshot(); +} + #[allow(dead_code)] #[doc = " # This is the enum's title "] #[doc = " This is "] @@ -55,13 +58,8 @@ enum MyEnum { } #[test] -fn doc_comments_struct() -> TestResult { - test_default_generated_schema::("doc_comments_struct") -} - -#[test] -fn doc_comments_enum() -> TestResult { - test_default_generated_schema::("doc_comments_enum") +fn doc_comments_enum() { + test!(MyEnum).assert_snapshot(); } /// # OverrideDocs struct @@ -82,6 +80,6 @@ struct OverrideDocs { } #[test] -fn doc_comments_override() -> TestResult { - test_default_generated_schema::("doc_comments_override") +fn doc_comments_override() { + test!(OverrideDocs).assert_snapshot(); } diff --git a/schemars/tests/integration/main.rs b/schemars/tests/integration/main.rs index e0f1ccbd..19529294 100644 --- a/schemars/tests/integration/main.rs +++ b/schemars/tests/integration/main.rs @@ -13,6 +13,7 @@ mod crate_alias; mod decimal; mod default; mod deprecated; +mod docs; mod prelude { pub use crate::test; diff --git a/schemars/tests/expected/doc_comments_enum.json b/schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_enum.de.json similarity index 100% rename from schemars/tests/expected/doc_comments_enum.json rename to schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_enum.de.json diff --git a/schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_enum.ser.json b/schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_enum.ser.json new file mode 100644 index 00000000..3c6e6801 --- /dev/null +++ b/schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_enum.ser.json @@ -0,0 +1,46 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "This is the enum's title", + "description": "This is \n the enum's description.", + "oneOf": [ + { + "type": "string", + "enum": [ + "UndocumentedUnit", + "UndocumentedUnit2" + ] + }, + { + "description": "This comment is included in the generated schema :)", + "type": "string", + "const": "DocumentedUnit" + }, + { + "title": "Complex variant", + "description": "This is a struct-like variant.", + "type": "object", + "properties": { + "Complex": { + "type": "object", + "properties": { + "my_nullable_string": { + "title": "A nullable string", + "description": "This field is a nullable string.\n\n This\nis\n the second\n line!\n\n\n\n\n And this is the third!", + "type": [ + "string", + "null" + ] + } + }, + "required": [ + "my_nullable_string" + ] + } + }, + "required": [ + "Complex" + ], + "additionalProperties": false + } + ] +} \ No newline at end of file diff --git a/schemars/tests/expected/doc_comments_override.json b/schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_override.de.json similarity index 100% rename from schemars/tests/expected/doc_comments_override.json rename to schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_override.de.json diff --git a/schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_override.ser.json b/schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_override.ser.json new file mode 100644 index 00000000..00eebe57 --- /dev/null +++ b/schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_override.ser.json @@ -0,0 +1,27 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "OverrideDocs struct", + "description": "New description", + "type": "object", + "properties": { + "my_int": { + "title": "My integer", + "description": "This is an i32", + "type": "integer", + "format": "int32" + }, + "my_undocumented_bool": { + "type": "boolean" + }, + "my_documented_bool": { + "title": "Documented bool", + "description": "CAPITALIZED", + "type": "boolean" + } + }, + "required": [ + "my_int", + "my_undocumented_bool", + "my_documented_bool" + ] +} \ No newline at end of file diff --git a/schemars/tests/expected/doc_comments_struct.json b/schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_struct.de.json similarity index 100% rename from schemars/tests/expected/doc_comments_struct.json rename to schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_struct.de.json diff --git a/schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_struct.ser.json b/schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_struct.ser.json new file mode 100644 index 00000000..670a4d26 --- /dev/null +++ b/schemars/tests/integration/snapshots/schemars/tests/integration/docs.rs~doc_comments_struct.ser.json @@ -0,0 +1,37 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "This is the struct's title", + "description": "This is the struct's description.", + "type": "object", + "properties": { + "my_int": { + "title": "An integer", + "type": "integer", + "format": "int32" + }, + "my_undocumented_bool": { + "type": "boolean" + }, + "my_unit": { + "description": "A unit struct instance", + "$ref": "#/$defs/MyUnitStruct" + }, + "my_documented_bool": { + "title": "Documented bool", + "description": "This bool is documented", + "type": "boolean" + } + }, + "required": [ + "my_int", + "my_undocumented_bool", + "my_unit", + "my_documented_bool" + ], + "$defs": { + "MyUnitStruct": { + "title": "A Unit", + "type": "null" + } + } +} \ No newline at end of file