Allow overriding title/desc from doc comments (#13)

This commit is contained in:
Graham Esau 2020-05-17 11:19:48 +01:00
parent 42e3c8fd7f
commit 1b42dc7e3e
7 changed files with 98 additions and 28 deletions

View file

@ -66,3 +66,22 @@ fn doc_comments_struct_ref_siblings() -> TestResult {
fn doc_comments_enum() -> TestResult {
test_default_generated_schema::<MyEnum>("doc_comments_enum")
}
/// # OverrideDocs struct
/// This description should be overridden
#[derive(Debug, JsonSchema)]
#[schemars(description = "New description")]
pub struct OverrideDocs {
/// # Overridden
#[schemars(title = "My integer", description = "This is an i32")]
pub my_int: i32,
/// # Overridden
/// Also overridden
#[schemars(title = "", description = "")]
pub my_undocumented_bool: bool,
}
#[test]
fn doc_comments_override() -> TestResult {
test_default_generated_schema::<OverrideDocs>("doc_comments_override")
}

View file

@ -0,0 +1,21 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "OverrideDocs struct",
"description": "New description",
"type": "object",
"required": [
"my_int",
"my_undocumented_bool"
],
"properties": {
"my_int": {
"title": "My integer",
"description": "This is an i32",
"type": "integer",
"format": "int32"
},
"my_undocumented_bool": {
"type": "boolean"
}
}
}