Redocly / redoc

📘 OpenAPI/Swagger-generated API Reference Documentation
https://redocly.github.io/redoc/
MIT License
23.61k stars 2.3k forks source link

Suggestion: Support x-enumNames extension #234

Open MattStaffordGS opened 7 years ago

MattStaffordGS commented 7 years ago

The x-enumNames extension (generated by NSwagStudio in our case) includes the human readable name of an enum when you're using integers for enum rather than strings It would be great if ReDoc could support being able to display what the integer element of an enum value means, rather than just the value

Currently it shows as Valid values: 0 1 2

Showing something like Valid values: Female (0) Male (1) Other (2) would be really useful

   "PersonGender": {
      "type": "integer",
      "x-enumNames": [
        "Female",
        "Male",
        "Other"
      ],
      "enum": [
        0,
        1,
        2
      ],
      "description": ""
    },
RicoSuter commented 5 years ago

Any update on this?

Content & configuration

It would be great if ReDoc could take x-enumNames into account if it is available. It is generated by the NSwag swagger toolchain and defines the enum names (not the values) and is useful for number enums (i.e. when the human readable names are missing).

Swagger/OpenAPI definition:

   "PersonGender": {
      "type": "integer",
      "x-enumNames": [
        "Female",
        "Male",
        "Other"
      ],
      "enum": [
        0,
        1,
        2
      ],
      "description": ""
    },

Is your feature request related to a problem?

Right now the generator has to generate a "special" description so that the user knows the mapping - but this is not very structured.

image

Describe the solution you'd like

If there's an x-enumNames property in an enum schema, render the name in the dropdown with the same index as the value and submit the correct enum value. This way the description is not needed anymore.

Describe alternatives you've considered

Right now we are using the description with the mappings - but that is not optimal...

Additional context

Refs:

hleb-albau commented 4 years ago

Is it different from x-enum-descriptions extension?