Is there a way to specify query parameter without value?

2,506 views
Skip to first unread message

Rick Sun

unread,
Jun 20, 2015, 11:14:37 AM6/20/15
to swagger-sw...@googlegroups.com
Consider two different REST request URLs:

In other words, whether parameter "deeplook" presents in the query makes a difference, regardless its value.
The closest I can get is to set deeplook as type boolean:
{
   "in": "query",
   "name": "deeplook",
   "type": "boolean",
   "required": false
}

SwaggerUi gives 3 choices: BLANK,true,false. Selecting BLANK gives req1: this is good. 
Selecting true gives me
Selecting false gives me

Swagger works as expected. However, my REST API treats req3 and req4 the same, i.e., it only looks whether deeplook presents or not and ignores its value.
My question is: is there a way to for swagger to specify query parameter with type "no_value"?

Rick Sun

unread,
Jun 20, 2015, 7:20:25 PM6/20/15
to swagger-sw...@googlegroups.com
The following gives user  two choices: "BLANK,true"
{
   "in": "query",
   "name": "deeplook",
   "type": "string",
   "required": false,
   "enum" : [ "true"]
}
This removes "false" from the dropdown list (req4), one step closer, but still not what I need.

Looking into the spec, found that "allowEmptyValue:true" should give me "?deeplook" with empty value:
Sets the ability to pass empty-valued parameters. This is valid only for eitherquery or formData parameters and allows you to send a parameter with a name only or an empty value. Default value is false.

"allows you to send a parameter with a name only" is exactly what I need. But I can't make it work.  The following gives me  "BLANK,BLANK" in dropdown, will not send the parameter:
{
                "in": "query",
                "name": "deeplook",
                "type": "string",
                "required": false,
                "enum" : [""],
                "allowEmptyValue" : true
}

Is allowEmptyValue supported now, if yes, is there an example, i.e., what "type" should be used, will it show "?deeplook" or "?deeplook=" ?

Ron Ratovsky

unread,
Jun 21, 2015, 1:11:46 AM6/21/15
to swagger-sw...@googlegroups.com
I believe allowEmptyValue is not yet supported by swagger-ui. If you need it, feel free to open an issue about it.
As for the representation, there's no clear definition and we'll have to clarify it.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Rick Sun

unread,
Jun 21, 2015, 7:48:37 AM6/21/15
to swagger-sw...@googlegroups.com
Ron, Thanks for the answer.  For now, swagger-ui treats BLANK value/choice as "do not send", so ui needs to come a new way to support allowEmptyValue=true.
I am thinking if swagger-ui can use the following rule to draw a "include this parameter" check box for a query parameter. When checked, then send "?parameter1", else do not send it at all. 
{
                "in": "query",
                "name": "parameter1",
                "type": "boolean",
                "required": false,
                "enum" : [true],
                "allowEmptyValue" : true
}
(1) "required" must be false
(2) "allowEmptyValue" must be true
(3) "enum" must have exactly one non-empty value
(4) "type" must be "boolean" (or "string" with a special enum, say "INCLUDE")

Not sure if this makes sense, and how hard it is to add this feature.
I still need to find out how to open an issue, this forum is the first time I post on internet.

Ron Ratovsky

unread,
Jun 21, 2015, 7:56:57 AM6/21/15
to swagger-sw...@googlegroups.com
Don't expect allowEmptyValue to work at all now, as it's simply not implemented.

As a side note, I hope the example you gave here is indeed just an example. API-design wise, it is very inconsistent.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rick Sun

unread,
Jun 21, 2015, 8:36:44 AM6/21/15
to swagger-sw...@googlegroups.com

Got it. I've not looked into details of swagger-ui design, just a wild thought for my simple case.


Just opened "Need a new feature to send a query parameter without value #1396".
Reply all
Reply to author
Forward
0 new messages