swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Data type Boolean renders empty droplist

Open stusta opened this issue 13 years ago • 12 comments

Using the latest from the develop-2.0 branch (commit b2637fc4bcb61bc92840200aea88055dbaa161f8), I've found these problems with parameters with a data type of boolean and a parameter type of form (Content-Type is application/x-www-form-urlencoded):

  • They are rendered with a list with no values in it.
  • When I tried setting booleanValues to an array of 0,1, I found that swagger.js wasn't setting a booleanValues property on SwaggerAPI. Once I hacked that, values were rendered in the list. But when I POSTed it, the field wasn't submitted.

stusta avatar Aug 07 '13 16:08 stusta

Hi, can you please retry this from master? it should be addressed.

fehguy avatar Aug 19 '13 15:08 fehguy

Please reopen if you see the issue still.

fehguy avatar Aug 19 '13 18:08 fehguy

Hi, I pulled in master and retried it. The boolean fields are still initially rendered with an empty list - there's no default values in it. (I can't work out how to pass in the desired values for boolean fields)

stusta avatar Aug 20 '13 12:08 stusta

Can you please share the JSON spec that you're displaying?

fehguy avatar Aug 20 '13 14:08 fehguy

I tried your latest change and it didn't make a difference.

Here's one of my API declarations that doesn't work (I've renamed a few things):

{
    "basePath": "http://internal.api.blah/v2/Products",
    "resourcePath": "/swagger/products",
    "swaggerVersion": "1.0",
    "apiVersion": "2.0",
    "consumes": [],
    "produces": [],
    "apis": [{
        "path": "/pricing/ad",
        "description": "Get Pricing for an Ad",
        "operations": [{
            "parameters": [{
                "name": "AdvertiserDomicile",
                "defaultValue": "1234",
                "description": "The Description",
                "dataType": "integer",
                "required": true,
                "allowMultiple": false,
                "paramType": "form"
            },
            {
                "name": "LocationId",
                "description": "The Location of the Job",
                "dataType": "integer",
                "required": false,
                "allowMultiple": false,
                "paramType": "form"
            },
            {
                "name": "ClassificationId",
                "description": "The Classification ID",
                "dataType": "integer",
                "required": false,
                "allowMultiple": false,
                "paramType": "form"
            },
            {
                "name": "WorkType",
                "description": "The Work Type",
                "dataType": "integer",
                "required": false,
                "allowMultiple": false,
                "paramType": "form"
            },
            {
                "name": "SalaryMin",
                "description": "The minimum Salary",
                "dataType": "decimal",
                "required": false,
                "allowMultiple": false,
                "paramType": "form"
            },
            {
                "name": "SalaryMax",
                "description": "The maximum Salary",
                "dataType": "decimal",
                "required": false,
                "allowMultiple": false,
                "paramType": "form"
            },
            {
                "name": "PayStructure",
                "description": "Pay Strucuture enumeration",
                "dataType": "integer",
                "required": false,
                "allowMultiple": false,
                "paramType": "form"
            },
            {
                "name": "IsStandout",
                "defaultValue": "false",
                "description": "True if the job is a Standout Ad",
                "dataType": "boolean",
                "required": false,
                "allowMultiple": false,
                "paramType": "form"
            },
            {
                "name": "IsPremium",
                "defaultValue": "false",
                "description": "True if the job is Premium Listing",
                "dataType": "boolean",
                "required": false,
                "allowMultiple": false,
                "paramType": "form"
            },
            {
                "name": "HasScreen",
                "defaultValue": "false",
                "description": "True if the job has a screen",
                "dataType": "boolean",
                "required": false,
                "allowMultiple": false,
                "paramType": "form"
            },
            {
                "name": "HasCustomTemplate",
                "defaultValue": "false",
                "description": "True if the job has a template",
                "dataType": "boolean",
                "required": false,
                "allowMultiple": false,
                "paramType": "form"
            }],
            "responseMessages": [],
            "method": "POST",
            "summary": "Returns a pricing result",
            "responseClass": "PricingResult",
            "nickname": "ProductPricing"
        }]
    }]
}

stusta avatar Aug 21 '13 12:08 stusta

Hi, I loaded your file and see the following. Looks correct to me?

screen shot 2013-08-21 at 1 23 22 pm

fehguy avatar Aug 21 '13 20:08 fehguy

if default is "false" in the @ApiParam annotation for my Boolean value, why does it always show "true" on the swagger UI?

rosselet avatar Sep 30 '14 17:09 rosselet

what type of parameter is it?

webron avatar Sep 30 '14 17:09 webron

My fault... "False" does not evaluate to "false" - I assumed that it used the same conventions for boolean as in java.. thank you. now it shows "false (default)"

rosselet avatar Sep 30 '14 19:09 rosselet

thank you.

fehguy avatar Sep 30 '14 20:09 fehguy

I'm on master and the following parameter list also causes the default value for "rememberMe" to be true (on Model Schema), even though I've explicitly set false as you can see below:

        ... other stuff ignored
        "parameters": [
          {
            "name": "loginData",
            "in": "body",
            "schema": {
              "type": "object",
              "properties": {
                "username": {
                  "type": "string",
                  "example": "admin"
                },
                "password": {
                  "type": "password",
                  "example": "admin"
                },
                "rememberMe": {
                  "type": "boolean",
                  "example": false
                }
              },

queirozfcom avatar Jun 10 '15 22:06 queirozfcom

Commenting on an issue that was closed two years ago doesn't help, @queirozfcom. It's definitely not related. Please open a new one. Also, you didn't set the default value, you set the example.

webron avatar Jun 10 '15 22:06 webron