Skip to content

Commit

Permalink
Port docs tests to new integration test style
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed Sep 9, 2024
1 parent 76d649a commit e7637bd
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 12 deletions.
22 changes: 10 additions & 12 deletions schemars/tests/docs.rs → schemars/tests/integration/docs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
mod util;
use schemars::JsonSchema;
use util::*;
use crate::prelude::*;

#[allow(dead_code)]
#[derive(JsonSchema)]
Expand All @@ -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 "]
Expand Down Expand Up @@ -55,13 +58,8 @@ enum MyEnum {
}

#[test]
fn doc_comments_struct() -> TestResult {
test_default_generated_schema::<MyStruct>("doc_comments_struct")
}

#[test]
fn doc_comments_enum() -> TestResult {
test_default_generated_schema::<MyEnum>("doc_comments_enum")
fn doc_comments_enum() {
test!(MyEnum).assert_snapshot();
}

/// # OverrideDocs struct
Expand All @@ -82,6 +80,6 @@ struct OverrideDocs {
}

#[test]
fn doc_comments_override() -> TestResult {
test_default_generated_schema::<OverrideDocs>("doc_comments_override")
fn doc_comments_override() {
test!(OverrideDocs).assert_snapshot();
}
1 change: 1 addition & 0 deletions schemars/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod crate_alias;
mod decimal;
mod default;
mod deprecated;
mod docs;

mod prelude {
pub use crate::test;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
]
}
Original file line number Diff line number Diff line change
@@ -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"
]
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

0 comments on commit e7637bd

Please sign in to comment.