swagger-ui
swagger-ui copied to clipboard
Optional array query params with enum are always sent after try out with non empty params
Q&A (please complete the following information)
- OS: macOS
- Browser: chrom
- Version: Chrome Version 72.0.3626.96 (Official Build) (64-bit)
- Method of installation: https://editor.swagger.io/
- Swagger-UI version: Not sure
- Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration
Example Swagger/OpenAPI definition:
openapi: '3.0.0'
info:
description: >-
Repro API
title: Repro API
version: '1.0'
paths:
/test:
get:
summary: Test get
parameters:
- name: fields
in: query
required: false
allowEmptyValue: false
schema:
type: array
items:
type: string
enum:
- friends
- family
example:
- friends
style: form
responses:
200:
description: Success!
content:
application/json:
schema:
type: object
properties:
id:
type: integer
name:
type: string
Swagger-UI configuration options:
Not sure; default?
No QueryStringConfig
Describe the bug you're encountering
To reproduce...
Steps to reproduce the behavior:
- Click on 'GET /test Test get'
- Click on 'Try it out'
- Deselect "friends" by command+click; Or select '--'
- Click on 'Execute'
- Check 'Request URL'
Expected behavior
Expect 'Request URL' being: https://editor.swagger.io/test
Screenshots
![screen shot 2019-02-12 at 11 41 38 am](https://user-images.githubusercontent.com/19319675/52663370-5917ba00-2ebb-11e9-8287-6ecd74a0507a.png)
Additional context or thoughts
This issue is similar to but different from #4223. There will be no problem if array items don't have enum. The example is not required. It is there just to give a non-empty value to start with. As mentioned in the title, I do need to do a try out with some value(s) like "friends" if there is no example. In another word, it seems I couldn't clear the field after the first, non-empty, try out.
Related: #4749
Is this PR going to be merged in the near future ?
@mu-majid this is not a pull request, it's a bug report.
the problem occurs when collectionFormat: "muiti" is not a problem. I hope this problem can be solved soon.
This issue forced us to modify our validation and allow an empty string (which is a sort of a hack) as a query param, it would be great if selecting "--" option would just simply not send that param instead of sending it empty.
@h4sohail as a work around you can Ctrl+Left Click on any previously selected values to unselect them, nevertheless I agree with your suggestion:
it would be great if selecting "--" option would just simply not send that param instead of sending it empty.
Why is this still open it looks kinda straight forward what the behaviour has to be. "allowEmptyValue": false, is default false so why is it possible to send a empty value with this setting on false.
has any solution been provided for this issue?
ctrl+ left click on previously selected values still sends empty value.
"allowEmptyValue": false is also not working.
has any solution been provided for this issue?
ctrl+ left click on previously selected values still sends empty value.
"allowEmptyValue": false is also not working.
I have a work around for this problem when the empty field is send i alter the request to not send this empty value.
(res: any) => {
var url = new URL(res.url);
if (url.searchParams.has('fields')) {
const fields = url.searchParams.get('fields');
if (fields.length === 0) {
url.searchParams.delete('fields');
} else {
let fixedFields = fields.split(',').filter((x) => x.length !== 0);
url.searchParams.set('fields', fixedFields.join(','));
}
res.url = url.href;
}
return res;
}
This method is ran on the requestIntercepter
has any solution been provided for this issue? ctrl+ left click on previously selected values still sends empty value. "allowEmptyValue": false is also not working.
I have a work around for this problem when the empty field is send i alter the request to not send this empty value.
(res) => { //Method to alter the fields param to do not send empty value ',' var url = new URL(res.url); if (url.searchParams.has('fields')) { const fields = url.searchParams.get('fields'); if (fields.length === 0) { url.searchParams.delete('fields'); } else { let fixedFields = fields.split(',').filter((x) => x.length !== 0); url.searchParams.set('fields', fixedFields.join(',')); } res.url = url.href; } return res; }
Hmm i dont know why my code is not getting correctly formated. But this methods is ran on the requestIntercepter
thank you for this. it works and I had to dynamically check and delete keys if they are null so with little changes I ended up with the following code:
(res: any) => {
var url = new URL(res.url);
url.searchParams.forEach(function(value, key) {
if (url.searchParams.has(key))
{
const values = url.searchParams.get(key);
if (values.length === 0) {
url.searchParams.delete(key);
} else {
let fixedValues = values.split(',').filter((x) => x.length !== 0);
url.searchParams.set(key, fixedValues.join(','));
}
res.url = url.href;
}
})
return res;
}
Also experiencing problems with -- being an available option to select in SwaggerUI for an enum parameter that has been specifically set to not allow empty values. This issue has been running for quite a while. Any chance of a fix in the near future? It is allowing users to send invalid requests.
Quite annoying problem. I'll be much appreciated if it can be fixed asap.
I also have the same problem, at least we need to able to remove '--' from the list.
It's been more than 3 years still not solved.
So, any progress? We would also like an option to remove the --
option
Any progress? I'm gonna cry. Why is this option --
available. I had to add a middleware and could not get rid of it because of that. It is super annoying. Is there any plan to drop the option from UI or arrange the curl call while trying out? I am willing to help, please let me know.
It's annoying when you have "--" option in list but can't remove it. It does make sense to show it in documentation if there is no need
Bumping this so that none gets tempted to think that this is a no-issue. It's actually broken :)
Bump
Please fix :)
Bump
Please fix :)
Please, fix ;-)
Please fix :)
Any update on this?
I recently ran into this issue as well. Either of the following solutions would be great:
- Remove the
--
option.- When nothing is selected, the query parameter is not in the request.
- Keep the
--
option.- When nothing is selected OR
--
is selected, the query parameter is not in the request
- When nothing is selected OR
Currently if I select the --
option, the query parameter is included in the request as empty.
Addressed by #9511