1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
mod util;
use schemars::{gen::SchemaSettings, JsonSchema};
use util::*;
#[allow(dead_code)]
#[derive(JsonSchema)]
/**
*
* # This is the struct's title
*
* This is the struct's description.
*
*/
struct MyStruct {
/// # An integer
my_int: i32,
my_undocumented_bool: bool,
/// A unit struct instance
my_unit: MyUnitStruct,
}
/// # A Unit
///
#[derive(JsonSchema)]
struct MyUnitStruct;
#[allow(dead_code)]
#[doc = " # This is the enum's title "]
#[doc = " This is "]
#[derive(JsonSchema)]
#[doc = " the enum's description."]
enum MyEnum {
UndocumentedUnit,
UndocumentedUnit2,
/// This comment is 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
/// the second
/// line!
///
///
///
///
/// And this is the third!
my_nullable_string: Option<String>,
},
}
#[test]
fn doc_comments_struct() -> TestResult {
test_default_generated_schema::<MyStruct>("doc_comments_struct")
}
#[test]
fn doc_comments_struct_ref_siblings() -> TestResult {
let settings = SchemaSettings::draft2019_09();
test_generated_schema::<MyStruct>("doc_comments_struct_ref_siblings", settings)
}
#[test]
fn doc_comments_enum() -> TestResult {
test_default_generated_schema::<MyEnum>("doc_comments_enum")
}
/// # OverrideDocs struct
/// This description should be overridden
#[allow(dead_code)]
#[derive(JsonSchema)]
#[schemars(description = "New description")]
struct OverrideDocs {
/// # Overridden
#[schemars(title = "My integer", description = "This is an i32")]
my_int: i32,
/// # Overridden
/// Also overridden
#[schemars(title = "", description = "")]
my_undocumented_bool: bool,
}
#[test]
fn doc_comments_override() -> TestResult {
test_default_generated_schema::<OverrideDocs>("doc_comments_override")
}
|