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

Route format mime type should be used #62

Open
ralpha opened this issue Oct 12, 2021 · 6 comments
Open

Route format mime type should be used #62

ralpha opened this issue Oct 12, 2021 · 6 comments
Labels
enhancement New feature or request rocket-okapi This affects the rocket-okapi crate rocket-okapi-codegen This affects the rocket-okapi-codegen crate

Comments

@ralpha
Copy link
Collaborator

ralpha commented Oct 12, 2021

Currently the format tag is ignored in routes.

#[openapi]
#[post("/create", data = "<data>", format = "text/plain")]
fn something(...) -> ...{
}

Screenshot from 2021-10-12 19-16-29
This should not be ignored but used.

This issue is also related to #10

@ralpha ralpha added the enhancement New feature or request label Oct 12, 2021
@ncpenke
Copy link

ncpenke commented Jan 13, 2022

Hi there, I took a stab at fixing this here: ncpenke@58e16cf. Please let me know if you're interested in taking it. I can open a PR and incorporate any further feedback.

Below is a screenshot with a modification to the json-web-api example. Thanks!

Screen Shot 2022-01-12 at 4 08 45 PM

@lukeb2e
Copy link

lukeb2e commented Jun 16, 2022

I just encountered the same issue.
If you have the invalid format type in the openapi spec, the api call is not working and returns a 404.
This is because the search now seems to check the format line, but the generated swagger page is then invalid.

PUT /v1/data/asdf application/octet-stream:
   >> No matching routes for PUT /v1/data/asdf application/octet-stream.
   >> No 404 catcher registered. Using Rocket default.
   >> Response succeeded.

If I manually set the format to application/octet-stream then my code is working as expected.

@lukeb2e
Copy link

lukeb2e commented Jun 21, 2022

I reproduced this issue in a small example application.

https://github.com/lukeb2e/rocket-openapi-format-swaggergen-bug

Even though the endpoint is configured to #[put("/<key>", data = "<data>", format = "text/plain")] the swagger only shows formatting for application/octet-stream. If this call is executed a 404 error is produced by the webserver. See screenshot below for generated swagger page, or check the example.

The fix from @ncpenke looks good to me, but then I only started to use rust a few days ago. ;)
So ping @GREsau ?

image

@jmdaly
Copy link

jmdaly commented Sep 15, 2022

I'm definitely being bitten by this one too. I'd like to POST some text as text/plain, but I can't get the Swagger interface to show anything other than application/octet-stream, which results in a 404 as others have mentioned above.

@ralpha ralpha added rocket-okapi This affects the rocket-okapi crate rocket-okapi-codegen This affects the rocket-okapi-codegen crate labels Dec 4, 2023
@jason-rietzke
Copy link

I also run in this unfortunate behaviour which makes it difficult to provide an easy to use API UI to test the interface with. Are there any plans to use the format annotation as described in this issue?
I think this would match the expected behaviour 🙂

@ralpha
Copy link
Collaborator Author

ralpha commented Apr 28, 2024

It would just depend on when I have time. And currently I'm not actively using this project much, so just doing maintenance. But if someone creates a MR I can review it and get it merged. So feel free to create one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rocket-okapi This affects the rocket-okapi crate rocket-okapi-codegen This affects the rocket-okapi-codegen crate
Projects
None yet
Development

No branches or pull requests

5 participants