additionalProperties: false
for struct annotated with serde deny_unknown_fields
(#30)
Co-authored-by: Denis Kurilov <denis@routinghub.com>
This commit is contained in:
parent
ea351f3b42
commit
1190b1fad9
4 changed files with 53 additions and 2 deletions
|
@ -362,12 +362,23 @@ fn expr_for_struct(fields: &[Field], cattrs: Option<&serde_attr::Container>) ->
|
|||
})
|
||||
.collect();
|
||||
|
||||
let deny_unknown_fields = cattrs
|
||||
.map_or(false, |attrs| attrs.deny_unknown_fields());
|
||||
|
||||
quote! {
|
||||
{
|
||||
#(#type_defs)*
|
||||
#set_container_default
|
||||
let mut schema_object = schemars::schema::SchemaObject {
|
||||
instance_type: Some(schemars::schema::InstanceType::Object.into()),
|
||||
object: Some(Box::new(schemars::schema::ObjectValidation {
|
||||
additional_properties: if #deny_unknown_fields {
|
||||
Some(Box::new(false.into()))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
..Default::default()
|
||||
})),
|
||||
..Default::default()
|
||||
};
|
||||
#(#properties)*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue