OpenAPITools / OpenAPITools/openapi-generator

[REQ] Better enum support in rust

Open
#10,977 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

Whilst I quite like this project, i found a problem arises with the rust enums. This arises when you have error enums which have no fields, such as in the pet store example:

responses:
  400:
    description: Invalid ID supplied
  404:
    description: Pet not found
  405:
    description: Validation exception

With the error codes 400, 404 and 405 since they have no content they will fail to convert into the enumerated response generated and so instead will have to be accessed via a response error.

Describe the solution you'd like

Rather than using #[serde(untagged)] I think it might be better to work based of status code. It might also be good to implement Display and Error on the error type using the description field.

Describe alternatives you've considered

So far in my project I have just been using the ResponseError sub variant instead, but this is clunky. Another option would be to separate the functionality mentioned above into an additional feature.

In addition a trait could be made such as DesieralizeWithStatusCode to ease the project.

Anyhow, many thanks with this project, it is so much easier than manually creating a reqwest library!

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

Start with the generated Rust response enums for the pet store example and examine how serde untagged handling treats status-code responses with no content. Compare that behavior with the proposed status-code-based deserialization, and consider the requested Display and Error implementations using the description field. Done means empty error responses deserialize into the generated enum without requiring ResponseError, with behavior covered for the 400, 404, and 405 cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.