Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-required Boolean value is always selected #1191

Closed
morficus opened this issue Apr 21, 2015 · 19 comments
Closed

non-required Boolean value is always selected #1191

morficus opened this issue Apr 21, 2015 · 19 comments
Assignees
Milestone

Comments

@morficus
Copy link

When defining a parameter of type boolean and required: false, the generated select-box in Swagger-UI only provides a "true" or "false" option forcing a value to be selected.
The expected behavior was that there would be a 3rd option with a blank value (because this is a non-required field)

YAML file:

swagger: "2.0"

info:
  description: Just to demonstrate a bug with non-requiered boolean values
  title: Bug Demonstration
  version: 0.0.0

paths:
  # This is a path endpoint. Change it.
  /projects:
    # This is a HTTP operation
    get:
      summary: List all projects
      description: Get a list of `Porject` objects.
      parameters:
        - name: isActive
          in: query
          description: filter active vs non-active projects
          required: false
          type: boolean
      # Expected responses for this operation:
      responses:
        # Response code
        200:
          description: Successful response
          # A schema describing your response object.
          # Use JSON Schema format
          schema:
            type: array
            items:
              $ref: '#/definitions/Project'

definitions:
  Project:
    properties:
      id:
        type: string
        description: Unique project identifyer
      name:
        type: string
        description: Project name
      isActive:
        type: boolean
        description: Is this an active project?

Viewer:
screen_shot_2015-04-21_at_4_58_15_pm

@FJavierGil
Copy link

Also, I think it would be better that the value assigned to the selected options was 1 or 0, not the string 'true' or 'false'

@webron
Copy link
Contributor

webron commented Apr 24, 2015

@FJavierGil - true/false is probably more understandable than 1/0, especially to non-developers, so we'll probably keep it as-is. Thank you for the suggestion though.

@FJavierGil
Copy link

I refer to "value" attribute, not the visible text.

@webron
Copy link
Contributor

webron commented Apr 24, 2015

That's not possible. The specification refers to boolean value as being true/false.

@FJavierGil
Copy link

Ok, Thank you.

@webron
Copy link
Contributor

webron commented Apr 24, 2015

If there's a field that you require to have the value of 1/0, I'd suggest setting it as an integer with an enum limiting to those values.

fehguy added a commit that referenced this issue Apr 28, 2015
fix #1191, forgot to put returns on handlebar helper
@firefoxNX
Copy link

Another variation to this defect -

parameters:
        - name: optBooleanDefaultFalse
          in: query
          type: boolean
          required: false
          default: false
          description: Optional parameter. Default is false

The optBooleanDefaultFalse dropdown shows up with value true.

@webron
Copy link
Contributor

webron commented Apr 29, 2015

That's not really a variation of this bug, it's a different one.

@ponelat
Copy link
Member

ponelat commented Apr 29, 2015

if you make false a string.."false", it'll have the behavior you expect. But I would like to see it behave the same, given a boolean.
I'll see what I can dig up...

@ponelat
Copy link
Member

ponelat commented Apr 30, 2015

The fix is in, and will eventually be in a release.
For now, if you'd like to see the default value of a boolean you can set the default to a string of that boolean. The fix will support both.

default: "false" // this will work now and in the fix
....
default: false // this will work in the fix

@morficus
Copy link
Author

awesome! 👍

@trobrock
Copy link

trobrock commented May 1, 2015

Is there a timeline or workaround for the optional value bug? I have a boolean that is optional and the default case is neither true or false.

@ponelat
Copy link
Member

ponelat commented May 1, 2015

That is by design, if the boolean is optional then we don't want to force either a true or false. In other words it would not send the parameter in the request. See the top comment that started this issue.

However, for clarification here is a comparison of what happens in the develop_2.0 branch (our dev branch)
And what happens in the fix...

From or dev branch...
in_develop_2 0


From the fix
bleeding_edge

@trobrock
Copy link

trobrock commented May 1, 2015

What you described as an optional boolean with no default value should not get sent is exactly what I'm looking for, but is not what I'm seeing in swagger-ui master. I also am not see the not required, no default case in the test cases you provided. Am I missing something somewhere?

@ponelat
Copy link
Member

ponelat commented May 1, 2015

Try with swagger-ui/develop_2.0 branch. It should look like the first screenshot.

@webron webron added the P1 label May 4, 2015
@webron webron added this to the v2.1 milestone May 4, 2015
@fehguy
Copy link
Contributor

fehguy commented May 8, 2015

looks like this is fixed now.

@fehguy fehguy closed this as completed May 8, 2015
@morficus
Copy link
Author

morficus commented May 8, 2015

🎉 🎊

@webron
Copy link
Contributor

webron commented May 10, 2015

@FJavierGil - going over the README, I just noticed the booleanValues property in the https://github.com/swagger-api/swagger-ui#parameters. It's not exactly what you want, but it may suit your needs.

@FJavierGil
Copy link

Great! Thank you very much!

Jonahss pushed a commit to eaze/swagger-ui that referenced this issue Aug 12, 2016
vincent-zurczak pushed a commit to roboconf/swagger-ui that referenced this issue Aug 19, 2016
vincent-zurczak pushed a commit to roboconf/swagger-ui that referenced this issue Aug 19, 2016
JuanSW18 pushed a commit to Digital-Paw/digital-paw-swagger-ui that referenced this issue Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants