Skip to content
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

how to document Path<> and Query with poem_openapi? #776

Open
rxdiscovery opened this issue Mar 18, 2024 · 2 comments
Open

how to document Path<> and Query with poem_openapi? #776

rxdiscovery opened this issue Mar 18, 2024 · 2 comments
Labels
question Further information is requested

Comments

@rxdiscovery
Copy link

Hello,

How to add a description to the :id parameter with #[aoi] poem_openapi,

 #[oai(path = "/user/:id", method = "get")]
    async fn hello(&self, Path(id): Path<String>) -> PlainText<String> {
        PlainText(format!("userid = {}", id))
    }

like this:

cap_id

and also for Url parameters (Query), http://xxxxxxxxxx/yyyy?param1=3 & param2=8784

@rxdiscovery rxdiscovery added the question Further information is requested label Mar 18, 2024
@rxdiscovery
Copy link
Author

rxdiscovery commented Mar 18, 2024

it's okay, I found out how :

here's an example of what to do if someone wants to do the same thing :

const ID_EXAMPLE: fn() -> String = || "id code".to_owned();

    #[oai(path = "/user/:id", method = "get")]
    async fn hello(&self, 
                          #[oai(name = "id", example = "ID_EXAMPLE")]
                          /// description here 
                           Path(id): Path<String>
                  ) -> PlainText<String> {
        PlainText(format!("userid = {}", id))
    }

example = "ID_EXAMPLE"
Why do we have to use double quotes when we're calling a function? "example =" won't accept an example in String format.

Poem is very feature-rich, and I'd like to congratulate you on a great piece of work, but unfortunately it lacks documentation and examples for this kind of scenario.

@sunli829
Copy link
Collaborator

Why do we have to use double quotes when we're calling a function? "example =" won't accept an example in String format.

Because there could be many different types, not just strings.

like this:
https://serde.rs/field-attrs.html#default--path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants