Skip to content

[REQ] Better enum support in rust #10977

@John-Toohey

Description

@John-Toohey

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions