Skip to content
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

Optional boolean as query parameter #339

Closed
allenpsuner opened this issue May 19, 2015 · 6 comments
Closed

Optional boolean as query parameter #339

allenpsuner opened this issue May 19, 2015 · 6 comments
Milestone

Comments

@allenpsuner
Copy link

I have an optional boolean query param in a GetAll Models function in this format:

        [ResponseType(typeof(IEnumerable<Foo>))]
        public IEnumerable<Foo> GetAll(bool? myBool = null)
        {
            if (myBool.HasValue)
            {
                return Repository.GetAll(Url).Where<Foo>(foo => foo.myBoolValue.Equals(myBool));
            }
            else
            {
                return Repository.GetAll(Url);
            }
        }

But in the swagger UI it doesn't behave like a true nullable.

screen shot 2015-05-19 at 3 40 26 pm

Is this a bug that is being worked on? Or is there a possible workaround that I should be using?

@monobjorn
Copy link

Maybe this has to do with Swagger UI? Have a look at: non-required Boolean value is always selected #1191

@allenpsuner
Copy link
Author

Maybe I should give some context. I'm using Swashbuckle because I heard that it was super easy to integrate into my .NET WebApi project. I'm pretty sure there are no YAML configs for Swashbuckle, so that thread doesn't really help me out. I'm 99% sure that this isn't a bug and I'm just doing something wrong, but Stack-Overflow wasn't being responsive quick enough.

@monobjorn
Copy link

I'm also new to Swashbuckle (just started using it the day before yesterday).
Swashbuckle generates a JSON specification of your service. This corresponds to the YAML mentioned in the issue.

I tried adding an optional boolean to my project and I got the same issue that you had. I then downloaded the newest version of swagger-ui and then it worked. So, it's not actually a Swashbuckle-issue.

@domaindrivendev
Copy link
Owner

@monobjorn is absolutely correct - this was a swagger-ui issue as opposed to a bug in SB itself.

I've upgraded to the latest swagger-ui and the issue is fixed. It will be available with the next release which I'm working hard to get out ASAP.

@allenpsuner
Copy link
Author

Awesome. Thank you so much @domaindrivendev.

@domaindrivendev
Copy link
Owner

Should be resolved in latest release - 5.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants