Set schema title and description from #[doc]s
Work in progress
This commit is contained in:
parent
c630264ef9
commit
feefd418d4
6 changed files with 262 additions and 47 deletions
53
schemars/tests/docs.rs
Normal file
53
schemars/tests/docs.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
mod util;
|
||||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
/**
|
||||
*
|
||||
* # This is the struct's title
|
||||
*
|
||||
* This is the struct's description.
|
||||
*
|
||||
*/
|
||||
pub struct MyStruct {
|
||||
/// # An integer
|
||||
pub my_int: i32,
|
||||
pub my_undocumented_bool: bool,
|
||||
/// A unit struct instance
|
||||
pub my_unit: MyUnitStruct,
|
||||
}
|
||||
|
||||
/// # A Unit
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct MyUnitStruct;
|
||||
|
||||
#[doc = " # This is the enum's title "]
|
||||
#[doc = " This is..."]
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[doc = "...the enum's description. "]
|
||||
pub enum MyEnum {
|
||||
UndocumentedUnit,
|
||||
/// This comment is not included in the generated schema :(
|
||||
DocumentedUnit,
|
||||
/// ## Complex variant
|
||||
/// This is a struct-like variant.
|
||||
Complex {
|
||||
/// ### A nullable string
|
||||
///
|
||||
/// This field is a nullable string.
|
||||
///
|
||||
/// This is another line!
|
||||
my_nullable_string: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
#[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")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue