question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting default value on an enum causes the default to always be used

See original GitHub issue
Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 2
Which Swagger-UI version? 3.2.2
How did you install Swagger-UI? Composer
Which browser & version? Chrome 61
Which operating system? Windows 10

Whenever a default is set on an enum parameter it becomes impossible to send another version than the default.

Demonstration API definition

swagger: '2.0'
host: localhost
info:
  title: Demo
  description: Demo
  version: 1.0.0
schemes:
  - https
consumes:
  - application/json
produces:
  - application/json
paths:
  '/demo':
    get:
      summary: Enum demo
      parameters:
        - name: enum_demo
          in: query
          required: true
          type: string
          default: first_value
          enum:
            - first_value
            - second_value
      responses:
        '200':
          description: Result
          schema:
            type: array
            items:
              type: object

Expected Behavior

The value selected in the dropdown box to be sent in the query string

Current Behavior

The default value is always sent in the query string

Possible Solution

Whenever you omit the default tag the request is fine

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
webroncommented, Oct 5, 2017

I wouldn’t dig too much into it. If the fix is there, it’ll roll into the editor in this week’s release because there’s definitely going to be one.

1reaction
BasKooijcommented, Oct 9, 2017

Yes, this look fine to me. The dropdown selects the default at first, and the right value appears in the query when I submit the request. I tried both with and without the required keyword and with default values that are not in the enum.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Choosing the default value of an Enum type without having to ...
The default for an enum (in fact, any value type) is 0 -- even if that is not a valid value for that...
Read more >
How To define a Default Value for an enum property ... - MSDN
I'm trying to use the default value attribute. But, when deserializing the default value is not set to what specified with ...
Read more >
c++ - Explicitly define enum values, even if the default value is ...
Incidentally, they are the same as the default values but does that mean it is no longer necessary to use explicit definitions? Leaving...
Read more >
Special values - Better Enums - GitHub Pages
Suppose your project has a convention where each enum has special invalid and default values — for example, Enum::Invalid is invalid, and the...
Read more >
Language Guide (proto3) | Protocol Buffers - Google Developers
For enums, the default value is the first defined enum value, which must be 0. For message fields, the field is not set....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found