Closed BertrandD closed 2 months ago
here is a test to reproduce the error:
use axum::extract::{Json, Path};
use oasgen::{oasgen, OaSchema, Server};
use serde::Deserialize;
/// Send a code to a mobile number
#[derive(Deserialize, OaSchema)]
pub struct TaskFilter {
pub completed: bool,
pub assigned_to: i32,
}
#[oasgen]
async fn get_task(Path(_id): Path<u64>) -> Json<()> {
Json(())
}
#[oasgen]
async fn get_stuff(Path((_id, _tu)): Path<(u64, u64)>) -> Json<()> {
Json(())
}
fn main() {
use pretty_assertions::assert_eq;
let server = Server::axum()
.get("/tasks/:id/", get_task)
.get("/stuff/:id/:tu", get_stuff);
let spec = serde_yaml::to_string(&server.openapi).unwrap();
let other = include_str!("03-path.yaml");
assert_eq!(spec.trim(), other);
let router = axum::Router::new().merge(server.freeze().into_router());
router.into_make_service();
}
Thanks for catching this.
I went through some refactors earlier this year that broke this. The fix is to remove the implementation for (A1, A2): OaSchema so that the blanket Path
Technically this is a breaking change, but because this was broken, I don't think it was plausibly being used. I cut as core=0.21.2 so the fix gets automatically pulled in for most people. Pulling that in should just be a cargo update
.
Hi ! Thank you for the quick fix ! I can get only the 0.21.1, and it fails compile with error " no impl_parameters
in the root", but it seems you already fixed it. Did you publish 0.21.2 ?
If you update oasgen itself (not core) as well, that should be fixed.
I'm realizing though that this approach might not work because it's causing a downstream probably. Might have another revision out later today.
I don't think fully fixing this was compatible possible without making breaking changes.
I split OaSchema into OaSchema & OaParameter, which I've been meaning to do for a while.
The rule of thumb for implementation is, implement OaSchema for "data types" and OaParameter for what I'll call "extractor types" - types that tell axum/actix/etc where to pull data out from the request or place it in the response.
Released the new version as 0.22. It has breaking changes for more advanced library usage, but the basics should be totally unchanged.
Let me know if you encounter any issues.
Hi,
Using axum, I have a query like that:
the point here is to have a tuple in the
Path
when starting the server, I get this error:
I digged a bit in the source code and expanded the #[oasgen] macro in my code and found that the issue come from there
where T is a tuple... And as the error says, we are not supposed to call schema() on a tuple... Are tuple supported anyhow ?
Thank you for your help !