-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Defining status code patterns results in syntax errors in the generated code of rust-server's mod.rs
because the rust-server template makes the assumption that the status codes are always numeric, but according to the OpenAPI specs it should be a string since it supports patterns such as 5XX which covers the range of 500-599 status codes all at once.
It's probably a more exotic/less often used feature, but nevertheless it sounds like a bug to me if it doesn't support something that the specs explicitly allows for.
openapi-generator version
The latest as of the time of this writing:
$ docker run --rm openapitools/openapi-generator-cli version
5.0.1-SNAPSHOT
OpenAPI declaration file content or url
I'm pretty sure that you can reproduce it with any spec file that uses status code patterns, but don't want to skimp on the details so also providing here the exact one I've been using.
Posting the JSON content raw as well because that link will die later as I finish work on my feature branch linked above:
https://gist.github.com/petermetz/243f80b31316c13c8975164e28fb3536
Generation Details
docker pull openapitools/openapi-generator-cli:latest
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate --input-spec https://raw.githubusercontent.com/petermetz/cactus/feat/cmd-api-server/out-of-process-plugin-Instances-for-language-Independence-170/packages/cactus-plugin-keychain-vault/src/main/json/openapi.json --generator-name rust-server -o /local/gen/rust-server
Steps to reproduce
Run the commands from the generation details
section above, then do
$ cargo run --example server
...
Compiling openapi_client v0.3.0 (/.../gen/rust-server)
error: invalid suffix `XX` for integer literal
--> src/client/mod.rs:461:13
|
461 | 5XX => {
| ^^^ invalid suffix `XX`
|
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)
error: invalid suffix `XX` for integer literal
--> src/client/mod.rs:559:13
|
559 | 5XX => {
| ^^^ invalid suffix `XX`
|
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)
error: invalid suffix `XX` for integer literal
--> src/server/mod.rs:214:99
|
214 | ... *response.status_mut() = StatusCode::from_u16(5XX).expect("Unable to turn 5XX into a StatusCode");
| ^^^ invalid suffix `XX`
|
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)
error: invalid suffix `XX` for integer literal
--> src/server/mod.rs:299:99
|
299 | ... *response.status_mut() = StatusCode::from_u16(5XX).expect("Unable to turn 5XX into a StatusCode");
| ^^^ invalid suffix `XX`
|
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)
error: aborting due to 4 previous errors
error: could not compile `openapi_client`
Related issues/PRs
N/A
Suggest a fix
I can tell as much that the issue is that generated code expects numeric values for the status codes instead of strings (which would allow the patterns to be valid syntax rust code).
No idea if this can be fixed just by simply changing the type of the relevant variable, or if it's a bigger refactoring job because maybe strings as keys is not allowed? (total rust beginner as you can probably tell)