Fix handling of attributes applied to unit variant types (#152)
This commit is contained in:
parent
9464118c3a
commit
76427ef384
7 changed files with 109 additions and 28 deletions
|
@ -31,7 +31,8 @@ struct MyUnitStruct;
|
|||
#[doc = " the enum's description."]
|
||||
enum MyEnum {
|
||||
UndocumentedUnit,
|
||||
/// This comment is not included in the generated schema :(
|
||||
UndocumentedUnit2,
|
||||
/// This comment is included in the generated schema :)
|
||||
DocumentedUnit,
|
||||
/// ## Complex variant
|
||||
/// This is a struct-like variant.
|
||||
|
|
|
@ -118,3 +118,21 @@ enum SimpleInternal {
|
|||
fn enum_simple_internal_tag() -> TestResult {
|
||||
test_default_generated_schema::<SimpleInternal>("enum-simple-internal")
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
enum SoundOfMusic {
|
||||
/// # A deer
|
||||
///
|
||||
/// A female deer
|
||||
Do,
|
||||
/// A drop of golden sun
|
||||
Re,
|
||||
/// A name I call myself
|
||||
Mi,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enum_unit_with_doc_comments() -> TestResult {
|
||||
test_default_generated_schema::<SoundOfMusic>("enum-unit-doc")
|
||||
}
|
||||
|
|
|
@ -6,7 +6,13 @@
|
|||
{
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"Unit",
|
||||
"Unit"
|
||||
]
|
||||
},
|
||||
{
|
||||
"deprecated": true,
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"DeprecatedUnitVariant"
|
||||
]
|
||||
},
|
||||
|
|
|
@ -7,6 +7,13 @@
|
|||
"type": "string",
|
||||
"enum": [
|
||||
"UndocumentedUnit",
|
||||
"UndocumentedUnit2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "This comment is included in the generated schema :)",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"DocumentedUnit"
|
||||
]
|
||||
},
|
||||
|
|
28
schemars/tests/expected/enum-unit-doc.json
Normal file
28
schemars/tests/expected/enum-unit-doc.json
Normal file
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "SoundOfMusic",
|
||||
"oneOf": [
|
||||
{
|
||||
"title": "A deer",
|
||||
"description": "A female deer",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"Do"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "A drop of golden sun",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"Re"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "A name I call myself",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"Mi"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue