GREsau / okapi

OpenAPI (AKA Swagger) document generation for Rust projects
MIT License
634 stars 112 forks source link

How to add a description for the route parameters #76

Closed lrodriguez14 closed 2 years ago

lrodriguez14 commented 2 years ago

Hello,

I want to know if there is any way to add a description to the route parameters?

For example:

/// # Get user
///
/// Returns a single user by ID.
#[openapi(tag = "Users")]
#[get("/user/<id>")]

How can I add a little description for ? As we can see in the image the description is empty image

Thanks!

ralpha commented 2 years ago

Create a custom type (so not just u64) and implement JsonSchema trait for it.

example:

#[derive(Serialize, Deserialize, JsonSchema, FromForm)]
struct Post {
    /// The unique identifier for the post.
    post_id: u64,
}

Example code: https://github.com/GREsau/okapi/blob/master/examples/json-web-api/src/main.rs#L74-L82

There does not currently exist a macro or something so do this easier. Other traits might be needed too for Rocket: https://rocket.rs/v0.5-rc/guide/requests/#query-strings In your case that is most likely: FromParam

ralpha commented 2 years ago

No response and no further action seems to be needed. Closing issue.

jiangxiaoqiang commented 2 years ago

I am facing the same issue. is it possible to support the easier way to do this issue?

ralpha commented 2 years ago

I am facing the same issue. is it possible to support the easier way to do this issue?

No, currently there is no other (easier) way of solving this. Otherwise we would have to create a macro that basically does the same. But this had not been created up until now.