parent
4b90b6f8c8
commit
1a40d1b06c
3 changed files with 15 additions and 1 deletions
|
@ -136,3 +136,11 @@ enum SoundOfMusic {
|
||||||
fn enum_unit_with_doc_comments() -> TestResult {
|
fn enum_unit_with_doc_comments() -> TestResult {
|
||||||
test_default_generated_schema::<SoundOfMusic>("enum-unit-doc")
|
test_default_generated_schema::<SoundOfMusic>("enum-unit-doc")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(JsonSchema)]
|
||||||
|
enum NoVariants {}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn enum_no_variants() -> TestResult {
|
||||||
|
test_default_generated_schema::<NoVariants>("no-variants")
|
||||||
|
}
|
||||||
|
|
6
schemars/tests/expected/no-variants.json
Normal file
6
schemars/tests/expected/no-variants.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
"title": "NoVariants",
|
||||||
|
"type": "string",
|
||||||
|
"enum": []
|
||||||
|
}
|
|
@ -162,7 +162,7 @@ fn expr_for_external_tagged_enum<'a>(
|
||||||
let unit_names = unit_variants.iter().map(|v| v.name());
|
let unit_names = unit_variants.iter().map(|v| v.name());
|
||||||
let unit_schema = schema_object(quote! {
|
let unit_schema = schema_object(quote! {
|
||||||
instance_type: Some(schemars::schema::InstanceType::String.into()),
|
instance_type: Some(schemars::schema::InstanceType::String.into()),
|
||||||
enum_values: Some([#(#unit_names),*].into_iter().map(|v| v.into()).collect()),
|
enum_values: Some(vec![#(#unit_names.into()),*]),
|
||||||
});
|
});
|
||||||
|
|
||||||
if complex_variants.is_empty() {
|
if complex_variants.is_empty() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue