OpenAPITools / OpenAPITools/openapi-generator
[BUG][Rust Server] Cannot compile client or server code when authorization is added
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
I generated rust server code using the rust-server generator but cargo/rustc won't compile, and leaves these messages:
error[E0277]: the trait bound `C: Has<std::option::Option<Authorization>>` is not satisfied
--> openapi-services/src/server/mod.rs:152:48
|
152 | let authorization = match (&context as &dyn Has<Option<Authorization>>).get() {
| ^^^^^^^^ the trait `Has<std::option::Option<Authorization>>` is not implemented for `C`
|
= note: required for the cast to the object type `dyn Has<std::option::Option<Authorization>>`
help: consider further restricting this bound
|
140 | C: Has<XSpanIdString> + Send + Sync + 'static + swagger::Has<std::option::Option<swagger::Authorization>>
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
This error occurs in client and server modules. Some error sites have a very similar error, but wants AuthData instead of (or in addition to) Authorization.
The swagger crate version that the generator provides is 5.0.2. I temporarily changed it to 5 and 6.1, but still failed to build.
openapi-generator version
Tried generator cli 5.2.0 and 5.3.0
OpenAPI declaration file content or url
securitySchemes:
OpenID:
type: openIdConnect
openIdConnectUrl: http://localhost:8080/auth/realms/testrealm/.well-known/openid-configuration
Command line used for generation
java -jar openapi-generator.jar generate -g rust-server -o openapi-services -i openapi.yaml --additional-properties=enablePostProcessFile=false,generateAliasAsModel=true,packageName=openapi_services,packageVersion=1.2.0
Steps to reproduce
Attempt to build using cargo.
$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home: /home/nathanw/.rustup
stable-x86_64-unknown-linux-gnu (default)
rustc 1.56.1 (59eed8a2a 2021-11-01)
Related issues/PRs
No bug PR's seem to relate to this.
Suggest a fix/enhancement
Update the C context types in mustache files to add Has<Option<swagger::Authorization>> and/or Has<Option<swagger::AuthData>> to client and/or server module code and example code that defines contexts.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure by generating the rust-server client and server with the shown OpenAPI security scheme, then run cargo build. Inspect the mustache templates for the generated client and server context bounds, including the example code. Done means generated code with authorization compiles for both modules without missing Authorization or AuthData trait bounds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100