Fix schema generation for complex enum variants
This commit is contained in:
parent
94250fa037
commit
936fb8c96e
3 changed files with 12 additions and 8 deletions
|
@ -2,14 +2,14 @@
|
|||
name = "schemars"
|
||||
description = "Generate JSON Schemas from Rust code"
|
||||
repository = "https://github.com/GREsau/schemars"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
authors = ["Graham Esau <gesau@hotmail.co.uk>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
keywords = ["rust", "json-schema", "serde"]
|
||||
|
||||
[dependencies]
|
||||
schemars_derive = { version = "0.1.0", path = "../schemars_derive" }
|
||||
schemars_derive = { version = "0.1.2", path = "../schemars_derive" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
name = "schemars_derive"
|
||||
description = "Macros for #[derive(MakeSchema)], for use with schemars"
|
||||
repository = "https://github.com/GREsau/schemars"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
authors = ["Graham Esau <gesau@hotmail.co.uk>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
|
|
@ -70,7 +70,7 @@ pub fn derive_make_schema(input: proc_macro::TokenStream) -> proc_macro::TokenSt
|
|||
}
|
||||
|
||||
fn make_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::Result {
|
||||
#schema
|
||||
Ok(#schema)
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -79,11 +79,11 @@ pub fn derive_make_schema(input: proc_macro::TokenStream) -> proc_macro::TokenSt
|
|||
|
||||
fn wrap_schema_fields(schema_contents: TokenStream) -> TokenStream {
|
||||
quote! {
|
||||
Ok(schemars::schema::Schema::Object(
|
||||
schemars::schema::Schema::Object(
|
||||
schemars::schema::SchemaObject {
|
||||
#schema_contents
|
||||
..Default::default()
|
||||
}))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,11 @@ fn schema_for_external_tagged_enum(variants: &[Variant], cattrs: &attr::Containe
|
|||
props.insert(#name.to_owned(), #sub_schema);
|
||||
props
|
||||
},
|
||||
required: vec![#name.to_owned()],
|
||||
required: {
|
||||
let mut required = schemars::Set::new();
|
||||
required.insert(#name.to_owned());
|
||||
required
|
||||
},
|
||||
})
|
||||
}));
|
||||
|
||||
|
@ -212,7 +216,7 @@ fn schema_for_struct(fields: &[Field], cattrs: &attr::Container) -> TokenStream
|
|||
let flattens = flat.iter().map(|f| {
|
||||
let ty = f.ty;
|
||||
quote_spanned! {f.original.span()=>
|
||||
?.flatten(<#ty>::make_schema(gen)?)
|
||||
.flatten(<#ty>::make_schema(gen)?)?
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue