GREsau / okapi

OpenAPI (AKA Swagger) document generation for Rust projects
MIT License
578 stars 103 forks source link

OpenAPI attribute fails to match query parameters to raw identifier function arguments #117

Closed alexjpayne closed 1 year ago

alexjpayne commented 1 year ago

When creating a route, if I use a query parameter with a name that corresponds to a Rust keyword (e.g. type), the openapi attribute macro fails to match the query parameter to the function argument. Presumably this is because the function argument has to be prepended with r# in order for rust to consider it as a raw identifier instead of the type keyword, and then the macro cant tell that type == r#type.

It appears this was an issue for rocket that was resolved a few years ago https://github.com/SergioBenitez/Rocket/issues/881. I'm certain that this is issue is with the openapi attribute, as if I use #[openapi(skip)] then everything works as expected.

I've created a branch with a new example demonstrating the problem: https://github.com/alexjpayne/okapi/tree/openapi_fails_to_match_raw_identifier_to_query_param

See: https://github.com/alexjpayne/okapi/blob/openapi_fails_to_match_raw_identifier_to_query_param/examples/raw_indentifiers/src/main.rs

ralpha commented 1 year ago

I used your example as a new test and fixed this issue. So this should work with the next version of this crate. Thanks for creating an issue for this.

alexjpayne commented 1 year ago

Thank you for fixing this, I appreciate it :slightly_smiling_face:

ralpha commented 1 year ago

No problem :) The new release was created the same day. So hope it works now, let me know if you find any other problems.