Fix #[schemars(with = ...)] alongside #[serde(transparent)] (#67)
Co-authored-by: Graham Esau <gesau@hotmail.co.uk>
This commit is contained in:
parent
1c9ecafd32
commit
c4ef7bad22
4 changed files with 43 additions and 26 deletions
|
@ -6,10 +6,11 @@
|
||||||
|
|
||||||
### Changed:
|
### Changed:
|
||||||
- Minimum supported rust version is now 1.37.0
|
- Minimum supported rust version is now 1.37.0
|
||||||
|
|
||||||
### Changed:
|
|
||||||
- Deriving JsonSchema on enums now sets `additionalProperties` to false on generated schemas wherever serde doesn't accept unknown properties. This includes non-unit variants of externally tagged enums, and struct-style variants of all enums that have the `deny_unknown_fields` attribute.
|
- Deriving JsonSchema on enums now sets `additionalProperties` to false on generated schemas wherever serde doesn't accept unknown properties. This includes non-unit variants of externally tagged enums, and struct-style variants of all enums that have the `deny_unknown_fields` attribute.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fix use of `#[serde(transparent)]` in combination with `#[schemars(with = ...)]` (https://github.com/GREsau/schemars/pull/67)
|
||||||
|
|
||||||
## [0.8.0] - 2020-09-27
|
## [0.8.0] - 2020-09-27
|
||||||
### Added:
|
### Added:
|
||||||
- `visit::Visitor`, a trait for updating a schema and all schemas it contains recursively. A `SchemaSettings` can now contain a list of visitors.
|
- `visit::Visitor`, a trait for updating a schema and all schemas it contains recursively. A `SchemaSettings` can now contain a list of visitors.
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
"title": "schema_fn",
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
|
@ -42,3 +42,12 @@ pub struct Newtype(#[schemars(schema_with = "schema_fn")] DoesntImplementJsonSch
|
||||||
fn struct_newtype() -> TestResult {
|
fn struct_newtype() -> TestResult {
|
||||||
test_default_generated_schema::<Newtype>("schema_with-newtype")
|
test_default_generated_schema::<Newtype>("schema_with-newtype")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, JsonSchema)]
|
||||||
|
#[schemars(transparent)]
|
||||||
|
pub struct TransparentNewtype(#[schemars(schema_with = "schema_fn")] DoesntImplementJsonSchema);
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn struct_transparent_newtype() -> TestResult {
|
||||||
|
test_default_generated_schema::<TransparentNewtype>("schema_with-transparent-newtype")
|
||||||
|
}
|
||||||
|
|
|
@ -38,10 +38,11 @@ fn derive_json_schema(mut input: syn::DeriveInput) -> TokenStream {
|
||||||
if let Some(transparent_field) = cont.transparent_field() {
|
if let Some(transparent_field) = cont.transparent_field() {
|
||||||
let (ty, type_def) = schema_exprs::type_for_schema(transparent_field, 0);
|
let (ty, type_def) = schema_exprs::type_for_schema(transparent_field, 0);
|
||||||
return quote! {
|
return quote! {
|
||||||
#[automatically_derived]
|
const _: () = {
|
||||||
impl #impl_generics schemars::JsonSchema for #type_name #ty_generics #where_clause {
|
|
||||||
#type_def
|
#type_def
|
||||||
|
|
||||||
|
#[automatically_derived]
|
||||||
|
impl #impl_generics schemars::JsonSchema for #type_name #ty_generics #where_clause {
|
||||||
fn is_referenceable() -> bool {
|
fn is_referenceable() -> bool {
|
||||||
<#ty as schemars::JsonSchema>::is_referenceable()
|
<#ty as schemars::JsonSchema>::is_referenceable()
|
||||||
}
|
}
|
||||||
|
@ -69,6 +70,7 @@ fn derive_json_schema(mut input: syn::DeriveInput) -> TokenStream {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut schema_base_name = cont.name();
|
let mut schema_base_name = cont.name();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue