You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a type with a generic type parameter that I don't want to be reflected in the schema at all:
use schemars::JsonSchema;use serde::{Deserialize,Serialize};use std::marker::PhantomData;#[derive(Serialize,Deserialize,JsonSchema)]#[serde(bound = "")]#[schemars(bound = "")]structFoo<In>{x:usize,#[serde(skip)]ph:PhantomData<In>,}
However, this won't compile:
error[E0599]: no function or associated item named `schema_name` found for type parameter `In` in the current scope
--> src/lib.rs:5:34
|
5 | #[derive(Serialize, Deserialize, JsonSchema)]
| ^^^^^^^^^^ function or associated item cannot be called on `In` due to unsatisfied trait bounds
...
8 | struct Foo<In> {
| -- function or associated item `schema_name` not found for this type parameter
|
= help: items from traits can only be used if the type parameter is bounded by the trait
= note: this error originates in the derive macro `JsonSchema` (in Nightly builds, run with -Z macro-backtrace for more info)
help: the following trait defines an item `schema_name`, perhaps you need to restrict type parameter `In` with it:
|
8 | struct Foo<In: JsonSchema> {
| ++++++++++++
error[E0599]: no function or associated item named `schema_id` found for type parameter `In` in the current scope
--> src/lib.rs:5:34
|
5 | #[derive(Serialize, Deserialize, JsonSchema)]
| ^^^^^^^^^^ function or associated item cannot be called on `In` due to unsatisfied trait bounds
...
8 | struct Foo<In> {
| -- function or associated item `schema_id` not found for this type parameter
|
= help: items from traits can only be used if the type parameter is bounded by the trait
= note: this error originates in the derive macro `JsonSchema` (in Nightly builds, run with -Z macro-backtrace for more info)
help: the following trait defines an item `schema_id`, perhaps you need to restrict type parameter `In` with it:
|
8 | struct Foo<In: JsonSchema> {
| ++++++++++++
The issue is that the generated code still tries to use In as though it implemented JsonSchema:
impl<In> schemars::JsonSchemaforFoo<In>{fnschema_name() -> std::string::String{::alloc::__export::must_use({let res = ::alloc::fmt::format(format_args!("Foo_for_{0}",In::schema_name()),);
res
})}fnschema_id() -> std::borrow::Cow<'static,str>{
std::borrow::Cow::Owned(::alloc::__export::must_use({let res = ::alloc::fmt::format(format_args!("schemars_bounds::Foo_for_{0}",In::schema_id()),);
res
}),)}// ...}
I can work around this by adding
#[serde(rename = "Foo")]
though not clear to me if that's an intended/expected behaviour?
The text was updated successfully, but these errors were encountered:
I have a type with a generic type parameter that I don't want to be reflected in the schema at all:
However, this won't compile:
The issue is that the generated code still tries to use
In
as though it implementedJsonSchema
:I can work around this by adding
#[serde(rename = "Foo")]
though not clear to me if that's an intended/expected behaviour?
The text was updated successfully, but these errors were encountered: