-
The goal is to maintain the single source of truth. For response body, we can use struct as the schema. Is it possible to do so for query (.e.g. fn get_doctor_details_doc() -> openapi::PathItem {
openapi::PathItem::builder()
.operation(
utoipa::openapi::HttpMethod::Get,
openapi::path::Operation::builder()
.response(
StatusCode::OK.as_u16().to_string(),
openapi::Response::builder().content(
"application/json",
openapi::Content::new(Some(GetDoctorDetailsResponse::schema())),
),
)
.response(
StatusCode::INTERNAL_SERVER_ERROR.as_u16().to_string(),
openapi::Response::builder().content(
"application/json",
openapi::Content::new(Some(InternalServerError::schema())),
),
)
.parameters(Some(vec![
openapi::path::Parameter::builder()
.name("before")
.description(Some(
"Cursor for pagination - return results before this doctor ID",
))
.parameter_in(openapi::path::ParameterIn::Query)
.required(utoipa::openapi::Required::False)
.build(),
openapi::path::Parameter::builder()
.name("after")
.description(Some(
"Cursor for pagination - return results after this doctor ID",
))
.parameter_in(openapi::path::ParameterIn::Query)
.required(utoipa::openapi::Required::False)
.build(),
openapi::path::Parameter::builder()
.name("limit")
.description(Some("Maximum number of results to return (default: 15)"))
.parameter_in(openapi::path::ParameterIn::Query)
.required(utoipa::openapi::Required::False)
.build(),
])),
)
.build()
}
#[derive(Deserialize, IntoParams)]
struct GetDoctorDetailsQuery {
before: Option<String>,
after: Option<String>,
limit: Option<usize>,
}
#[derive(Serialize, ToSchema)]
struct GetDoctorDetailsResponse {
next_cursor: Option<String>,
rows: Vec<DoctorDetail>,
}
|
Beta Was this translation helpful? Give feedback.
Answered by
lamualfa
Oct 13, 2025
Replies: 1 comment
-
You can. But it's undocumented i think: openapi::path::Operation::builder()
.parameters(
Some(
GetDoctorDetailsQuery::into_params(|| {
Some(ParameterIn::Query)
})
)
) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lamualfa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can. But it's undocumented i think: