juhaku / utoipa

Simple, Fast, Code first and Compile time generated OpenAPI documentation for Rust
Apache License 2.0
2.49k stars 197 forks source link

Name variants on enum with ``repr`` #1181

Closed RubberDuckShobe closed 3 weeks ago

RubberDuckShobe commented 3 weeks ago

Hello, I have an enum like this:

#[derive(ToSchema)]
#[repr(i16)]
pub enum AccountType {
    User,
    Moderator,
    Team,
}

In the OpenAPI spec that was generated, it only shows the integers, with no name at all: image-67~2

Is there a way to specify the name for enum variants? It'd be great to be able to have the names in the spec as well.

juhaku commented 3 weeks ago

I would say this is a duplicate for this #954. Since enums in general are represented in JSON Schema as enum: [...] There is no way to add any description on them. https://json-schema.org/understanding-json-schema/reference/enum.

While this doc is for OpenAPI 3.0 https://swagger.io/docs/specification/v3_0/data-models/enums/ it contains an example of how to leverage a description field to further expand what the enums contains.

Also if you remove the repr(i16) you will get enum that shows the names only. But those are the options basically. Anything else would need the enum itself not being represented as an enum but a type constructed from allOf and other attributes necessary to represent type with name.

RubberDuckShobe commented 3 weeks ago

Thanks for the help, I'll see. Sorry for the duplicate