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

Openapi default value for simple query parameter #941

Open
rsJames-ttrpg opened this issue Dec 31, 2024 · 0 comments
Open

Openapi default value for simple query parameter #941

rsJames-ttrpg opened this issue Dec 31, 2024 · 0 comments
Labels
question Further information is requested

Comments

@rsJames-ttrpg
Copy link

I have a paginated endpoint and want the documentation to say the default values for the query params I think I might be missing something simple:

    #[oai(
        path = "/stuff",
        method = "get",
        tag = super::ApiTags::Stuff,
        operation_id = "list-stuff"
    )]
    async fn list_stuff(
        &self,
        #[oai(default)] page: Query<Option<i64>>,
        #[oai(default)] per_page: Query<Option<i64>>
    ) -> ListStuffResponse {
        let page: i64 = page.0.unwrap_or(1);
        let per_page = per_page.0.unwrap_or(10);
        ...
    }

I have to do the unwrap_or and the information is not documented but the functionality works.

The approaches I have tried wrapping i64 and implementing default trait. Then I need to write my own api adapter traits etc. It seems like I am missing something simple here.

@rsJames-ttrpg rsJames-ttrpg added the question Further information is requested label Dec 31, 2024
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

1 participant