-
Notifications
You must be signed in to change notification settings - Fork 476
Allow empty security array for endpoints #729
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
Conversation
09549a0
to
4f9df95
Compare
This makes total sense, I have merged this. |
@fotos You can make another PR for the remaining things with tests, please. Much appreciated, thanks for the good work! |
@dblock thanks. 🙇 I'll iterate on another PR and trim the unnecessary Is it possible to get |
Happy to make a release soon if @LeFnord is not around, let's see that other PR :) |
I'm here, but need a bit to have a look on all the new stuff 😉 |
Fixes a bug where empty arrays for endpoints (operations) are excluded from the generated schema.
The OpenAPI 2.0 spec for
security
:This is useful in the following scenario:
You define a top level
security
requirement (e.g.OAuth2
) that applies to the whole API and then selectively whitelist endpoints that are public.For example:
Which renders like this in
Swagger UI
:Note the absence of 🔓 for
/users
.There are a couple of more places where
#blank?
is used inGrape::Endpoint
. Namely in#swagger_object
,#info_object
,#license_object
, and#contact_object
. I didn't change those since, for example, the#license_object
can't be blank (needs at least aname
).This change will produce empty arrays in
#method_object
, for keys such asparameters
ortags
. The generated schema is still valid since an emptyparameters
ortags
is allowed. Especially for parameters it's allowed to override / amend (if defined) but not to remove. The empty array is successfully ignored bySwagger UI
. This PR will make the generated schema a bit more verbose yet, still, valid. Another alternative is to callObject#presence
in#params_object
and#tag_object
.In the last commit I remove the default empty
description
to bring the generated schema (and specs) closer to what they were originally (before this PR).☝️ Let me know whether I should include / make those changes.