| 1 | use crate::prelude::*; |
| 2 | |
| 3 | #[allow(dead_code)] |
| 4 | #[derive(JsonSchema)] |
| 5 | /** |
| 6 | # This is the struct's title |
| 7 | |
| 8 | This is the struct's description. |
| 9 | */ |
| 10 | struct MyStruct { |
| 11 | /// # An integer |
| 12 | my_int: i32, |
| 13 | my_undocumented_bool: bool, |
| 14 | /// A unit struct instance |
| 15 | my_unit: MyUnitStruct, |
| 16 | #[doc = concat!("# Documented ", "bool")] |
| 17 | #[doc = concat!("This bool is documented")] |
| 18 | my_documented_bool: bool, |
| 19 | } |
| 20 | |
| 21 | /// # A Unit |
| 22 | #[derive(JsonSchema)] |
| 23 | struct MyUnitStruct; |
| 24 | |
| 25 | #[test] |
| 26 | fn doc_comments_struct() { |
| 27 | test!(MyStruct).assert_snapshot(); |
| 28 | } |
| 29 | |
| 30 | #[allow(dead_code)] |
| 31 | #[doc = " # This is the enum's title "] |
| 32 | #[doc = " This is "] |
| 33 | #[derive(JsonSchema)] |
| 34 | #[doc = " the enum's description."] |
| 35 | enum MyEnum { |
| 36 | UndocumentedUnit, |
| 37 | UndocumentedUnit2, |
| 38 | /// This comment is included in the generated schema :) |
| 39 | DocumentedUnit, |
| 40 | /// ## Complex variant |
| 41 | /// This is a struct-like variant. |
| 42 | Complex { |
| 43 | /// ### A nullable string |
| 44 | /// |
| 45 | /// This field is a nullable string. |
| 46 | /// |
| 47 | /// This |
| 48 | ///is |
| 49 | /// the second |
| 50 | /// line! |
| 51 | /// |
| 52 | /// |
| 53 | /// |
| 54 | /// |
| 55 | /// And this is the third! |
| 56 | my_nullable_string: Option<String>, |
| 57 | }, |
| 58 | } |
| 59 | |
| 60 | #[test] |
| 61 | fn doc_comments_enum() { |
| 62 | test!(MyEnum).assert_snapshot(); |
| 63 | } |
| 64 | |
| 65 | /// # OverrideDocs struct |
| 66 | /// This description should be overridden |
| 67 | #[allow(dead_code)] |
| 68 | #[derive(JsonSchema)] |
| 69 | #[schemars(description = "New description")] |
| 70 | struct OverrideDocs { |
| 71 | /// # Overridden |
| 72 | #[schemars(title = "My integer", description = "This is an i32")] |
| 73 | my_int: i32, |
| 74 | /// # Overridden |
| 75 | /// Also overridden |
| 76 | #[schemars(title = "", description = "")] |
| 77 | my_undocumented_bool: bool, |
| 78 | #[schemars(title = concat!("Documented ", "bool"), description = "Capitalized".to_uppercase())] |
| 79 | my_documented_bool: bool, |
| 80 | } |
| 81 | |
| 82 | #[test] |
| 83 | fn doc_comments_override() { |
| 84 | test!(OverrideDocs).assert_snapshot(); |
| 85 | } |