-
Notifications
You must be signed in to change notification settings - Fork 463
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
Add support for defining headers for API methods. #341
Conversation
partially closes #340 |
Thanks for this 😎 ! |
@alan-andrade Good point, working on it |
@alan-andrade Done, will do rebase after 'plus one' |
👍 good beginning! (next, we should be able to add validation on the headers) |
@mtparet I was thinking about validation, do we really need it? As I know, header is always a class SomeController
def some_action
request.headers.keys.map(&:class).uniq
# => [String]
end
end Even if it comes to server as request.headers['SERVER_PORT']
# => '3000' |
Maybe just checking that the required headers are present… |
@iNecas do you mean passing |
Yes require should be enough (I was thinking about the |
@mtparet |
Any other comments/missing stuff? I was going to add tests for views, but I couldn't find spec files. |
@IlyaBylich I meant the validate_presence (https://github.com/Apipie/apipie-rails#id20) support for the headers, where,when enabled, it would fail if it's not there. But I can live with this just being documented somewhere. |
No tests for views so far in apipie, no need to add them for this PR |
@IlyaBylich I mean I'm not sure there are cases for which we need to verify the presence of a header except when we need to require a precondition HTTP header. (the absence of a precondition HTTP header could result to a 428 HTTP status) |
3f20652
to
08159eb
Compare
Added small note that headers can't be validate with P.S. Just a little question about |
class ResourceDescription | ||
|
||
attr_reader :controller, :_short_description, :_full_description, :_methods, :_id, | ||
:_path, :_name, :_params_args, :_errors_args, :_formats, :_parent, :_metadata | ||
:_path, :_name, :_params_args, :_errors_args, :_formats, :_parent, :_metadata, | ||
:_headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\ 😃 /
|
👞 👞
This is great ! Thanks <3
@iliabylich the validations is maybe the most controversal feature. People either love it or don't understand why it's even there :) The motivation for it was, given it's ruby code anyway, and it has enough data for doing the checking, why not just leveraging that information. The benefits are:
So yes, it doesn't belong to a conventional documentation tool. However, the apipie is quite unconventional :) ACK from the code perspective: leaving some time for others also confirming they are ok with this PR (seems more people got interested). Expecting a new version with this released early next week |
@iNecas ok, it makes sense, I would like to add headers validation (but probably in another PR). And it's nice to hear that you going to release it so soon, I need it in my current project 😄 |
Add support for defining headers for API methods.
New version 0.3.3, with the change was just released. Thanks @iliabylich |
@iNecas Thanks for releasing! |
Keys included in pull request: Apipie#341
This is awesome ! <3 Thanks everyone |
Hi, what about auto generation headers in docs based on functional tests? It would be a pretty cool feature. |
I think good idea will be provide an option, to specify list of necessary headers that will be automatically include to docs based on tests. |
@yaneq6 Any ideas how to differentiate default rails/rack/whatever headers and custom headers? And very often your headers-related stuff like authentication is mocked in your tests, so you can't fetch headers because you just don't have it. |
@iliabylich As I said, "good idea will be provide an option, to specify list of necessary headers". I mean, everyone who would use this feature should specify list of header in their own scope, somewhere in the config files (maybe apipie.rb or application.rb, whatever...) and only that headers should be automatically included in documentation. But please, don't expect from me any pull request, actually my rails skills are to low and i am not able to implement this feature on my own. |
Missing the following in generation. add_headers_from_hash(swagger_result, method.resource._headers) if method.resource._headers.present? |
@byjus-taha-abbas this PR is 7 years old... |
To be honest, I couldn't find the tests for views, so I've added tests only for model part. I will add missing tests as soon as somebody tells me where they are 😄