-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[axum][v3.4.0] Option<Query<T>> causes a build error #677
Comments
The actual build error occurred in our project is: Other build errors can be fixed by simply adding |
Oh bummer, I'll make a test for this case today and try to find a way to solve this issue, It somehow thinks the |
@masnagam A quick fix for this is to wrap the actual parameter with the async fn get_item(id: Query<Option<u32>>) {} This way the compile will work. And most likely it should mark the parameter as non-required. But if it is defined with manually as you did above, it will will be (or at least should be) required because of explisit type declaration without
|
There is actually a fundamental issue in See the comment for further explanation #678 (comment) |
Thank you for taking your time for this issue.
I tried this quick fix and confirmed that it can fix the build error but one of our unit tests fails.
I confirmed that 99020a9 can fix the original issue I reported but the following test causes another (but a similar) build error: #[test]
fn test_into_params_for_option_query_wrapped_u32() {
#[derive(Deserialize, IntoParams)]
#[into_params(names("id"))]
struct Id(u32);
#[utoipa::path(
get,
path = "/items",
params(("id" = Option<u32>, Query, description = "")),
responses(
(status = 200, description = "success response")
)
)]
#[allow(unused)]
async fn get_item(id: Option<Query<Id>>) {}
#[derive(OpenApi)]
#[openapi(paths(get_item))]
struct ApiDoc;
}
And this is our case. We use a type wrapping a primitive type (the linked source file is for v3.3.0 and it works without The workaround we found is like this: #[test]
fn test_into_params_for_option_query_wrapped_u32() {
// We no longer need to implement the following traits on `Id` in this test case.
//#[derive(Deserialize, IntoParams)]
//#[into_params(names("id"))]
struct Id(u32);
#[utoipa::path(
get,
path = "/items",
params(("id" = Option<u32>, Query, description = "")),
responses(
(status = 200, description = "success response")
)
)]
#[allow(unused)]
async fn get_item(id: Option<Query<u32>>) { // use the inner type here
// convert it into the outer type
let id = id.map(|Query(id)| Query(Id(id)));
// and then call the original function renamed to `do_get_item`
do_get_item(id).await
}
async fn do_get_item(_id: Option<Query<Id>>) {}
#[derive(OpenApi)]
#[openapi(paths(get_item))]
struct ApiDoc;
} This works fine with 99020a9. I'm not familiar with procedual macros, generating code like the one above might solve this issue if possible. |
Eh, this is parameter rabbit hole is getting deeper and deeper 🤣 I can also make a quick fix for this, but it does not completely solve the issue which causes yet another side effect that is, then the This might indicate that there is actually a bigger rework to be done for what comes to the parameters that need to take place in some timeframe. |
True. It might be better to give up to automatically generate Currently, we face the build error that I reported even if we explicitly add Automatically generating Is there any workaround to avoid the build error without modifying the naive implementation? For example, specifying a particular filed in |
At the moment no, the only 2 options are to use previous version 3.3.0 or the workarounds discussed in this issue.
Yeah, it might be as good to just wait for the better implementation that solves the edges that the current one is lacking. |
Thank you for your reply. OK. I keep this ticket open and stop updating
|
Temporarily disable automatic parameter recognition. This is to mitigate the current issues in `IntoParams` implementation furhter discussed in issues #675 #677 #687. This commit restores the old behavior where the parameters must be declared with `params(...)` attribute within the `#[utoipa::path(...)]` attribute macro. The temporary disablement is to allow furhter releases not be blocked by the changes in the master branch. The automatic parameter recognition still needs some work and most likely another approach need to experiemented before it can be finally completed.
The old parameter behavior is restored in #696. I'll make new release soon with the changes. More about this here #675 (comment). |
Temporarily disable automatic parameter recognition. This is to mitigate the current issues in `IntoParams` implementation furhter discussed in issues juhaku#675 juhaku#677 juhaku#687. This commit restores the old behavior where the parameters must be declared with `params(...)` attribute within the `#[utoipa::path(...)]` attribute macro. The temporary disablement is to allow furhter releases not be blocked by the changes in the master branch. The automatic parameter recognition still needs some work and most likely another approach need to experiemented before it can be finally completed.
We could upgrade to 3.4.3 without any changes in our code. Thank you for taking your time for this issue. |
The following test can pass in v3.3.0:
But it fails building in v3.4.0 due to the following error:
Query<T>
works fine in the both versions.Using
git bisect run ...
, I confirmed that #666 causes this issue.Maybe, an issue similar to #675 (comment) occurs in
axum
.The text was updated successfully, but these errors were encountered: