-
Notifications
You must be signed in to change notification settings - Fork 313
Description
I've been on utoipa 5.4.0 using rocket for a while now and suddenly encountered this issue. I found that my path parameters for some of my routes were missing in the generated docs.
For example, one of my routes looks like this:
/// Fetch a project by ID
/// Requires user to belong to either the vendor or customer organization
#[utoipa::path(
context_path = "/project",
tag = "Project",
responses(
(status = 200, description = "Project fetched successfully", body = ProjectFull),
ApiErrorResponse<FetchProjectError>,
)
)]
#[get("/<project_id>")]
pub async fn fetch_project(
mut db: Connection<Db>,
auth: InOrg<ValidSession>,
project_id: ProjectPublicId,
) -> Result<Json<ProjectFull>, ApiErrorResponse<FetchProjectError>> {But it was missing the project_id path parameter.
For reference ProjectPublicId is a wrapper around a String, and it has a manual ToSchema impl. Basically:
struct PublicId<T>(String);
impl<T> PartialSchema for PublicId<T>
where
T: IdType,
{
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
String::schema()
}
}
impl<T> ToSchema for PublicId<T>
where
T: IdType,
{
fn name() -> std::borrow::Cow<'static, str> {
"public_id".into()
}
}I did some digging, and I found the code responsible:
utoipa/utoipa-gen/src/ext/rocket.rs
Lines 138 to 151 in a024aca
| fn is_into_params(fn_arg: &FnArg) -> bool { | |
| let mut ty = &fn_arg.ty; | |
| if fn_arg.ty.generic_type == Some(GenericType::Option) { | |
| ty = fn_arg | |
| .ty | |
| .children | |
| .as_ref() | |
| .expect("FnArg Option must have children") | |
| .first() | |
| .expect("FnArg Option must have 1 child"); | |
| } | |
| matches!(ty.value_type, ValueType::Object) && ty.generic_type.is_none() | |
| } |
This function is miss-classifying these parameters as "IntoParams" parameters (if im reading the code correctly). Forcing this function to return false fixes my issue.
Strangely, when I implemented IntoParams for this type, the implementation was never called during generation.