the trait `OperationOutput` is not implemented for `axum_jsonschema::Json<T>`
dpasirst opened this issue · 9 comments
I suspect the problem is that the published version of axum-jsonschema is 0.6.0
instead of 0.7.0
- that is, the latter does not appear to be a released version for use in cargo. Attempting to use 0.6.0
with aide 0.12.0
results in the trait OperationOutput is not implemented for axum_jsonschema::Json<T>
for both derive OperationIo and impl OperationOutput
Reproduce using aide/examples/example-axum
by modifying aide/examples/example-axum/Cargo.toml
to specify:
axum-jsonschema = { version = "0.6.0" , features = [
"aide",
] }
instead of axum-jsonschema = { path = "../../crates/axum-jsonschema"
...
This results in:
error[E0277]: the trait bound `axum_jsonschema::Json<T>: OperationOutput` is not satisfied
--> examples/example-axum/src/extractors.rs:10:23
|
10 | #[derive(FromRequest, OperationIo)]
| ^^^^^^^^^^^ the trait `OperationOutput` is not implemented for `axum_jsonschema::Json<T>`
|
= help: the following other types implement trait `OperationOutput`:
...
you can use the new WithApi
wrapper type, it's a bit convoluted right now:
#[derive(Debug)]
struct JsonOverride<T>(PhantomData<T>);
impl<T> ApiOverride for JsonOverride<T> {
type Target = axum_jsonschema::Json<T>;
}
impl<T> OperationInput for JsonOverride<T> {
// delegate the OperationInput from the old json
}
async fn my_handler(WithApi(ty, ..): WithApi<JsonOverride<SomeType>>) {
// use the parsed json from ty
}
Another alternative is to make a wrapper like we did with aide-axum-sqlx-tx
Thank You. I'm looking over both options for my existing project. On the surface, both of these seem a bit non-intuitive. I'll explore more today.
it's unfortunately the only way when you need to implement a trait on a type from two different external crates in the current state of rust
I was looking through the change in github and the reason, so I see why it was done, but my attempt to convert is not going smoothly. Is there an updated version of https://github.com/tamasfe/aide/tree/master/examples/example-axum to demonstrate implementing these changes?
The reason it was done is beacause we have conflicting versions of every dependency crate, so the traits are often implemented on the wrong version. this new method allows external crates to handle these dependencies with wrappers. The easiest is types that have no associated openapi spec, then you can just extract with fn(NoApi(type): NoApi<T>)
I think we could add a special WithApi type specific to schema so that you can use WithSchema<Json<T>, T>
if T
is JsonSchema
@dpasirst you're right actually, it's a version issue. @tamasfe can you give me the rights to publish the new version of axum-jsonschema ?
sorry, I forgot about this, I've just invited you on crates.io.