-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Omit empty and optional values in form data #5303
Comments
Having said that, how would we expect this to work? Consider this html form <form action="https://httpstat.us/200" method="get">
<input type="text" name="name" />
<input type="text" name="nick" />
<input type="submit" value="Submit" />
</form> If you submitted that, any values you hadn’t entered still get added as query parameters so it still ends up making a request to So while I think there is the potential to have an “Ignore empty values” option I don’t think swagger-ui should assume that because it’s an optional parameter and it’s empty that it shouldn’t be sent at all. Does that make sense? cc/ @milanlatinovic |
Hi Simon, These are my thoughts related to current issue (maybe it will be helpful). From the business process view:
Ideal case:
From a technical side:
Maybe I missed something here or I understood it wrong. What would be the best thing to do here? I am open to help in any kind of testing from our side to sort this out. Kind regards, |
I try to describe the API problem in depth. For my case, the API has POST operation
In the case when I want to choose both attributes, I send this request:
It means that the name attribute should be changed to value Unfortunately, I can not simulate this behavior within Swagger-UI. It is not possible to omit any defined optional parameter in a HTTP request and if the value is empty my API accepts it as empty string - it is a valid value, but I also need to have a choice to omit this parameter. |
Hi everyone, Just wanted to quickly check the state of this issue? Was there any idea on how and when this would be resolved? Did this make it to some refined backlog or maybe even sprint plan? :) Quick note, this issue has also appeared in #5314 Let me know if I can provide any further info to make resolving of this issue easier. Kind regards, |
I would vote for adding a checkbox to all optional parameters within the Swagger UI (it could be checked by default). But, I need to have the option to uncheck this checbox and tell Swagger UI, that I don't want to send this parameter in the HTTP request... |
@propi agreed, checkbox to turn on / turn off empty parameters (like Postman interface does) would be a quick and good solution. But in any case, I think this should be handled as soon as possible, because at this point (at least for my company) Swagger UI is not useful, because our API execution does not work. Meanwhile: @leggsimon if you know some kind of simple/dirty patch to completely turn off empty parameters, I would be very thankful. This would solve our issue and help us continue using Swagger UI. All best, |
Sorry @milanlatinovic I’ve been on holiday which was why I haven’t got back to this.
I don’t know personally. I don’t make any particular decisions about the project at the moment or have insight as to where it’s going. Having said that I also don’t know of any reasons why a PR would be rejected to add this feature (that’s not to say others might not have opposing views).
Unfortunately I don’t. Regarding a potential solution, I think that @propi’s suggestion of having checkboxes for each parameter makes the most sense. I’m wondering though whether there should be the same functionality for toggling empty headers & query parameters as well as request bodies. Would either of you have thoughts there? I’m inclined to say the same should apply. I did start an attempt at this before and it is a little bit fiddly so might take a bit of time to get a good solution, but I may give it another go this weekend. One last thing, regarding #5314, I wonder if that issue should be closed in favour of keeping the discussion here? |
Hi @leggsimon, not a problem at all. I hope your holiday was good. :)
Yup, same should apply in my opinion as well.
Yup, we can close this one and focus on finding and delivering a solution within this thread. Thanks, I will be free to check in on a status of this issue from time to time. Meanwhile, let me know if there is anything that I can do or help from my side. |
So I had a little look at this over the weekend and although I’m not completely familiar with the project it seems like quite a complicated implementation. I’m not sure if I’m going to have much time soon to get to a real fix (although I’ve written some failing e2e tests to cover the implementation which I’ll try and push up). I’m just going to write what I’ve found so far in case some else has a bit more time. Parameters allow for an Since Request Bodies don’t support this property in the spec that component is never used in the flow of rendering the Request Body “form”. The Request Body is rendered initially here and the actual form fields are described in In order to omit any empty values via a checkbox I think one of 2 things needs to happen.
My preferred approach would be 2 personally since I think it makes it a little more semantically correct, however I think it is the most amount of work and would possibly be a breaking change depending on how this project deems changes to be breaking. |
True, I agree, 2nd approach would be more semantically correct. allowEmptyValue and current checkboxes implementation is not useful because it is not covering requestBody properly. @leggsimon thank you once more for looking into this and documenting your findings. |
Has this issue been handling? |
liv1n9 nope, not that I know... whole year, not a step forward :) |
I also wanted this feature, so I implemented it and sent a Pull Request. |
Added back in #6227. |
I have this request body:
If I send a request wihin Swagger UI with some
name
but with empty value in thenick
field, the UI evaluates the request like this:curl -X POST "address" -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "name=vaclav&nick="
But I need not to have the
nick
field contained in the request body if the field is empty, like this:curl -X POST "address" -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "name=vaclav"
Can I mark a property field as optional and not sending if the field is empty? Unfortunately, my API does not accept empty values, but it is able to omit some post field if it is not included in a request.
The text was updated successfully, but these errors were encountered: