swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.47k stars 8.96k forks source link

Parameter with Enum as well manual enter #4856

Open SSCodeChamp opened 6 years ago

SSCodeChamp commented 6 years ago

Hi,

The enum parameter is a great feature. I have a requirement where user can select from enum or he can enter the value he want. This is useful when the value is not available in the enum set.

shockey commented 6 years ago

This isn't something we could do by default - the purpose of enum is to express "only these values can be used".

I'd be open to a vendor extension for this though, maybe something like x-allow-custom-values.

SSCodeChamp commented 6 years ago

Thanks Shockey. That would be great if you could add that to the vendor extension.

blackat commented 5 years ago

A question about enum, the swagger-maven-plugin generates an empty enum

{
  "openapi" : "3.0.1",
  "info" : {
    "title" : "My Rest API",
    "description" : "My RESTful API implementation",
    "version" : "1.0.0"
  },
  "servers" : [ {
    "url" : "/{context-path}/{rest-api}",
    "description" : "My REST API",
    "variables" : {
      "context-path" : {
        "default" : "my-war"
        "enum" : [ "" ]
      },
      "rest-api" : {
        "default" : "api",
        "enum" : [ "api", "rest", "batchapi" ]
      }
    }
  } ],
...

}

The empty enum is rendered as an empty dropdown, is it correct? If I remove the empty enum I have an input field with the default value.

Here the full issue description I have open into swagger code.

Swagger core version 2.0.6 and I have tested against the deployed version of swagger-ui as well.

Thanks in advance 😉

shockey commented 5 years ago

@blackat, this is intentional - if you have an enum you should include your default value in it. Swagger Core should generate enums accordingly, so this is a bug on their side.