Swagger-ui: Execute button issue when one of the parameters is boolean

Created on 18 Jul 2017  路  20Comments  路  Source: swagger-api/swagger-ui

I'm using swagger-ui version 3.0.19, have discovered weird behaviour occurring when one of the parameters is type boolean. After loading page 'Execute' button is active, but cannot be clicked (no reaction). The solution is changing the value of boolean from/to true/false and after this 'Execute' will be able to perform some action. The interesting fact is, that if we add to parameter definition "default: true" is working from the beginning, but not for "default: false". @shockey Can you have a look ?

swagger: "2.0"
info:
  version: "1.0.0"
  title: "someName"
host: "localhost:8080"
basePath: "/rest"
tags:
- name: "someTag"
schemes:
- "http"
paths:
  /search/receiptTime:
    get:
      tags:
      - "someTag"
      summary: "someSummary"
      description: "someDescription"
      operationId: "someOperationId"
      produces:
      - "application/json"
      - "application/xml"
      parameters:
      - name: "nodeIndexName"
        in: "query"
        required: true
        type: "string"
      - name: "excludeTime"
        in: "query"
        required: true
        type: "boolean"
        default: true
definitions:
lock-bot bug

Most helpful comment

@owenconti I see it now, yes you are right. The previous fix solves the issue, we can close it now.

All 20 comments

This is most likely a bug I introduced. @shockey I can look into it if it is alright with you.

@owenconti, sure, go for it! I discovered a possibly related bug, going to file it in a moment. Will ping you in the issue.

Hi @kwieconkowski, I cannot reproduce this issue. This is the spec I am trying: http://petstore.swagger.io/?url=https://gist.githubusercontent.com/owenconti/d38603a95558b200299713a926624cf3/raw/c77d53e262df80066eb3c1d427a0be2822f6eb4f/gistfile1.txt

Please try with my example to reproduce, and let me know the steps if you can get the issue to happen again.

Hi @owenconti , I have some problems reproducing it now, but found a similar issue. Please, follow exactly in the same order. Open webpage that you provided, copy into 'Explore' field following link (the same definition, but without 'default' value inside):

https://gist.githubusercontent.com/kwieconkowski/f17ad4a2974d9b4a7e892420e951d56f/raw/79234f7bbb72dee4b8681cea7bfc16f7e4547abe/test.yaml

Fill up just 'nodeIndexName' and press 'Execute'. There will be an infinite rotation animation and following exception in a browser console:

swagger-ui-bundle.js:22625 Uncaught Error: Required parameter excludeTime is not provided
    at swagger-ui-bundle.js:22625
    at Array.forEach (<anonymous>)
    at Object.o [as buildRequest] (swagger-ui-bundle.js:22625)
    at swagger-ui-bundle.js:7673
    at swagger-ui-bundle.js:5415
    at swagger-ui-bundle.js:63039
    at swagger-ui-bundle.js:22625
    at Object.r [as executeRequest] (swagger-ui-bundle.js:42813)
    at swagger-ui-bundle.js:7673
    at swagger-ui-bundle.js:5415

Screenshot

If boolean is required and no default value provided, it should have an additional state like 'None' and not allow sending any requests.

The infinite loading animation bug has been filed here: https://github.com/swagger-api/swagger-ui/issues/3414

I have a fix and will be creating a PR this evening.

@webron What do you think about @kwieconkowski's suggestion of defaulting Boolean params that do not have a default specified to 'None'?

Yeah - that makes sense, only instead of 'None' value, it should just be an empty value.

Hi @kwieconkowski, this should be fixed in the latest release (3.0.20). Could you please update to that version and see if you can still reproduce the issue? I will close this issue for now, but feel free to re-open if you still experience troubles.

I'm using release 3.0.21 with a spec that has this:

      in: formData
      name: active
      required: true
      type: boolean

The dropdown box defaults to true, but if I try to submit the request, nothing happens. It seems the default value is empty, but the UI doesn't indicate the value is missing (no shaking red box). Visually it looks like true, but in the React component the value is an empty string.

@owenconti I think we talked about the above use-case? Having a blank value by default and red/wiggle it if required.

This was rolled back with 3.0.21.

@owenconti I have tested on version 3.0.21, doesn't work as already @kingjerod mentioned. When a field is required, it shows as 'true' value, but no request is sent and no indication that something is missing (shaking field). There will be a fix for it ?

@kwieconkowski, the feature will be reimplemented in https://github.com/swagger-api/swagger-ui/pull/3453. I need to review it, but I'm hoping to have that done today so the feature can be released on Friday.

Thanks for your patience!

Hi @kwieconkowski, could you please try testing again against version 3.1.1?

Hi @owenconti and @shockey , I have tested and its works. Great job, I have last suggestion if I may share. When boolean is required, we can choose --/true/false, but a request is only sent when selecting true/false - I like that. But when boolean is not mandatory, currently you can even choose '--' and a request will be sent (value will be false). Maybe this should be blocked (the same way when boolean is required), because it may be confusing what value is send under '--' by for example business people. I think that when boolean is required, should be '--' preselected (currently working like this) and when not required and default value missing, then 'false' preselected (and not allowing sending request when '--'). In this way, for significant fields user always will be notified and for others, he/she won't even notice. Just give it a thought, currently is also working great

@owenconti I tend to agree. If a boolean parameter is not required, and -- is selected, it shouldn't send any value at all.

@kwieconkowski I'm having trouble reproducing what you mentioned. Can you try this spec and let me know if you can reproduce it? Or if there is another way to reproduce it?

http://petstore.swagger.io/?url=https://gist.githubusercontent.com/owenconti/97429f8569e0600a482f03a1174f8f5e/raw/ed483343e8385a45a3d54a736d9134508fe414ff/gistfile1.txt#/

Hi @owenconti @webron , I have reproduced it on a first try using your example link. When you have a resource: '/pet/findByStatus' and press 'Execute' is shaking on 'required' field, this is good. If you will read my previous post carefully, I was suggesting that for 'optional' field should also shake and not allow to send any request for '--'. Right now, if you will not modify 'optional' (left as '--') and set 'required' as 'true/false' it will send a request (don`t want that).

I was suggesting for clarity purposes, that even when a field is not required it must show a valid value. For boolean by default Swagger should switch in webpage/GUI from '--' to 'false' for 'optional' field, because we don`t want to block user -> '--' this should always be blocking/shaking, even if a field is not required.

I'm of the opinion that boolean types should be treated the same as all other types, string, integer, etc. With that, optional fields that are not filled out do not send the parameter in the request. See my screenshot below for an example with an optional string and optional boolean and notice how neither are sent in the request.

By forcing the user to choose a value for optional boolean types, we are essentially making every boolean type required.

I believe @webron agrees:

webron commented 19 hours ago - @owenconti I tend to agree. If a boolean parameter is not required, and -- is selected, it shouldn't send any value at all.

screen shot 2017-08-01 at 6 44 01 am

@owenconti I see it now, yes you are right. The previous fix solves the issue, we can close it now.

I can reproduce this issue on swagger-ui version 3.22.0

Was this page helpful?
0 / 5 - 0 ratings