Fix handling of attributes applied to unit variant types (#152)

This commit is contained in:
Adam Leventhal 2022-08-12 07:37:34 -07:00 committed by GitHub
parent 9464118c3a
commit 76427ef384
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 109 additions and 28 deletions

View file

@ -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.

View file

@ -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")
}

View file

@ -6,7 +6,13 @@
{
"type": "string",
"enum": [
"Unit",
"Unit"
]
},
{
"deprecated": true,
"type": "string",
"enum": [
"DeprecatedUnitVariant"
]
},

View file

@ -7,6 +7,13 @@
"type": "string",
"enum": [
"UndocumentedUnit",
"UndocumentedUnit2"
]
},
{
"description": "This comment is included in the generated schema :)",
"type": "string",
"enum": [
"DocumentedUnit"
]
},

View 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"
]
}
]
}