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: Using external request-guards makes documenting impossible #113

Closed
open-schnick opened this issue Aug 30, 2022 · 3 comments
Closed

Comments

@open-schnick
Copy link

In cases where a crate provides a type and a request-guard implementation it is not possible to document endpoints using that type.
This was an error for the rocket_db_pools::Connection<T> type and fixed by implementing that trait in this crate in pr #104.
I have the same error now with a different type.
Obviously we cannot do that for every crate that interacts with rocket.
The only way to fix this would be to be able to skip some parameters in the route definition.
This was already requested in #85.
Sadly i am currently not able to create a pr for that but i would imagine it like so:

#[openapi(ignore = ["param"])]
#[get("/")]
pub fn index(param: ExternalType) -> &'static str {
    // logic
}

My really stupid, but working workaround is to define the same route again, documenting it, and removing the not working parameter.

// the actual route
#[openapi]
#[get("/", rank = 1)]
pub fn index(param: ExternalType) -> &'static str {
    // logic
}

// duplicated route without actual logic but incremented rank
#[openapi]
#[get("/", rank = 2)]
pub fn index_but_documented() -> &'static str {
  // nothing but a warning
}

Obviously that is not really cool.
The only way is see to fix this would implement said ignore attributes.
What do you think?

@ralpha
Copy link
Collaborator

ralpha commented Oct 12, 2022

I would have to look further into this. But this looks definitely like something worth looking into more.

I think the ignore approach also looks good. I will see if I can quickly get this solved.

@ralpha ralpha closed this as completed in b5b0a89 Oct 12, 2022
@ralpha
Copy link
Collaborator

ralpha commented Oct 12, 2022

Solved in master, see https://github.com/GREsau/okapi/blob/master/examples/openapi_attributes/src/main.rs#L14 for an example.
I'll document it and other derive attributes later.
Right now it works on everything except path parameters because I think this would always give unwanted results.

It will also give compiler errors when the argument does not exist and when it is a path parameter.

Multiple attributes can also be ignored using: #[openapi(ignore = "db", ignore = "log")]

See if this solves your problem. If not or you find a bug, let me know so I can fix it before the next release.

@open-schnick
Copy link
Author

Very cool thank you for implementing that <3

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

2 participants