Setting default value on an enum causes the default to always be used
See original GitHub issueQ | 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:
- Created 6 years ago
- Comments:15 (11 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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.