OpenAPITools / OpenAPITools/openapi-generator

[BUG][rust-server] Unable to turn 5XX into a StatusCode invalid suffix `XX`

Open
#8,401 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Rust
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

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.

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

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the listed rust-server generation command with the linked OpenAPI declaration, then inspect the generated src/client/mod.rs and src/server/mod.rs where 5XX produces Rust syntax errors. Trace those outputs back to the rust-server template and verify that the generated project compiles successfully with cargo run --example server for status-code patterns.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, rust
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.