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

rocket::http::Status as oapi responder #20

Closed
l4l opened this issue Apr 8, 2020 · 3 comments
Closed

rocket::http::Status as oapi responder #20

l4l opened this issue Apr 8, 2020 · 3 comments
Assignees

Comments

@l4l
Copy link

l4l commented Apr 8, 2020

It seems that rocket::http::Status does not implement OpenApiResponder, so that simple route will fail:

use rocket::http::Status;

#[get("/")]
fn func() -> Status { Status::Ok }

It's quite tricky, because the interface is not supposed to have access to the object itself, only type. As a temporary workaround l4l@9206ab2 may work, though I don't really think it's a good idea to merge it.

Maybe some wrapper should be considered for statuses? Procedural macros cannot properly determine whether the item is particular type or not in general, afaik, although they may emit warnings for a wrapper hinting.

@megametres
Copy link

megametres commented May 16, 2020

I think that it is safe to assume that if a route return's type is a rocket::http::Status when everything goes as expected the returned status will be Status::Ok. If not, I think that implementing something like #[okapi(return_code = "404")] would be the best course of action, altough I do not have a clue if it would be hard doing so...

@GREsau
Copy link
Owner

GREsau commented May 24, 2020

Related: #15 (comment)

@ralpha ralpha self-assigned this Sep 8, 2021
@ralpha
Copy link
Collaborator

ralpha commented Sep 9, 2021

This has been fixed in 1740ebc.
Okapi now uses the "default" setting in OpenAPI: https://spec.openapis.org/oas/v3.0.0#fixed-fields-13
Screenshot from 2021-09-09 18-19-27
Screenshot from 2021-09-09 18-21-23

This is a screenshot of the example: https://github.com/GREsau/okapi/blob/master/examples/special-types/src/main.rs#L17
It also works with just the rocket::http::Status (or other combination you might expect, like Result<Json<()>, rocket::http::Status>)
The documentation for these endpoint might be a bit scarce, because there is not much info that can be displayed.

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

No branches or pull requests

4 participants