-
Notifications
You must be signed in to change notification settings - Fork 219
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
Schema options in params(...) are ignored #804
Comments
Thanks for reporting this. The issue you referred might be something similar. E.g. In one the parameters behave differently when the |
Thanks for your quick response, and sorry for reacting so late myself.
Since this issue removes attributes from our API spec that we need to keep, this currently blocks us from upgrading to utoipa 4. Is there some way I can help with this? |
Hey again @juhaku, I did some investigation around the code, and I think I've found one way to fix a simple test case (like the one I mentioned above, a string parameter with a min_length feature), but I'm not sure how robust it is, so you should definitely also look at this yourself (and we should maybe add more test cases). The simple test case can look like this: // in utoipa-gen/tests/path_derive_axum_test.rs
#[test]
fn path_param_primitive_arg_with_additional_settings() {
#[utoipa::path(
get,
path = "/items/{id}",
params(
("id", min_length = 1),
),
responses(
(status = 200, description = "success response")
)
)]
#[allow(unused)]
async fn get_item(id: Path<String>) {}
#[derive(OpenApi)]
#[openapi(paths(get_item))]
struct ApiDoc;
let doc = serde_json::to_value(ApiDoc::openapi()).unwrap();
let operation = doc.pointer("/paths/~1items~1{id}/get").unwrap();
println!("{:?}", operation.pointer("/parameters"));
assert_json_eq!(
operation.pointer("/parameters"),
json!([
{
"in": "path",
"name": "id",
"required": true,
"schema": {
"type": "string",
"minLength": 1, // without the fix, this property will be missing
}
}
])
)
} As you suggested, the main issue seems to be that some information from the explicit parameter info is overwritten with information extracted from axum: Basically, it needs to repeat these three lines from the Parse function: utoipa/utoipa-gen/src/path/parameter.rs Lines 262 to 265 in 1ea9cf8
I'm not sure if we also need to move the features from The above test case works with this adjusted version of the merge function: pub fn merge(&mut self, other: Parameter<'p>) {
match (self, other) {
(Self::Value(value), Parameter::Value(other)) => {
value.parameter_schema = other.parameter_schema;
// not sure if this is needed:
let (mut schema_features, mut param_features) = other.features;
value.features.0.append(&mut schema_features);
value.features.1.append(&mut param_features);
// same logic as in Parse():
if let Some(pf) = &mut value.parameter_schema {
pf.features = value.features.0.clone();
}
}
(Self::IntoParamsIdent(into_params), Parameter::IntoParamsIdent(other)) => {
*into_params = other;
}
_ => (),
}
} I'd also like some feedback from exploring and fiddling with the code (but I'm aware that I just dove in for some very isolated things, so feel free to ignore this if you think otherwise): As a pure refactoring, I recommend making Furthermore, it seems to be errorprone that the Finally, I wonder if it would make the code easier to understand to split |
Hi @juhaku! Happy new year! 🎉 Just wanted to check in, are there any updates on this? |
Hello, and sorry for this taking so long, 😞 I am now taking this under work. |
True, that indeed fixes this issue with params, thanks for noticing. That above both is needed since that will be needed in |
When `axum_extras`,`actix_extras` or `rocket_extras` was enabled the udpate of existing parameters did not take in account the features that was defined in the tuple style arguments and was overridden with empty features. This PR fixes this behavior where features will be also updated accordingly. Resolves #804
When `axum_extras`,`actix_extras` or `rocket_extras` was enabled the udpate of existing parameters did not take in account the features that was defined in the tuple style arguments and was overridden with empty features. This PR fixes this behavior where features will be also updated accordingly. Resolves #804
When `axum_extras`,`actix_extras` or `rocket_extras` was enabled the udpate of existing parameters did not take in account the features that was defined in the tuple style arguments and was overridden with empty features. This PR fixes this behavior where features will be also updated accordingly. Resolves #804
Hi utoipa folks! First of all, thank you very much for your great work on this library, it has helped us a bunch to manage our API spec!
We're just trying to update from v3.3.0 to v4.1.0, and it seems that additional schema options in
params(...)
inside of the#[utoipa::path(...)]
now get ignored 🥲We're using axum and have the axum feature in utoipa turned on.
For example, we have an endpoint similar to this (reduced to essential stuff):
With v3.3.0, this used to emit something like this in the OAPI doc:
With v4.1.0, the
minLength: 1
gets removed from the OAPI doc output :(Randomly, I also tried adding the
nullable
annotation to the same parameter, i.e. turning it into:In v4.1.0, this didn't affect the output at all.
In v3.3.0, this changed the output as expected:
Is this a known issue? I looked around in the issues, but couldn't find one that exactly seems to match this problem (but could be that the description/title is too different.)
The only slightly similar issue I could find is #693, but I'm not sure if that one might be a separate problem affecting only
format
🤔If there's something we can do to help isolate this, please let me know!
The text was updated successfully, but these errors were encountered: