Apipie / apipie-rails

Ruby on Rails API documentation tool
Apache License 2.0
2.47k stars 463 forks source link

Add possibility to define custom headers response #706

Closed nexxus-vi closed 5 months ago

nexxus-vi commented 3 years ago

Hi, i'm using pagy in an API Only project to paginate model's index. This gem provides additional header in response, such as

Link - <http://localhost:3000/api/v1/accounts?page=1>; rel="first", <http://localhost:3000/api/v1/accounts?page=1>; rel="last"

Current-Page - 1

Page-Items - 2

Now i can add headers for request like this:

header 'Authorization', 'Bearer [your_access_token]', required: true
header 'Content-Type', 'application/json', required: true
header 'Accept', 'application/json', required: true

but how about headers for response?

davidwessman commented 7 months ago

@PanosCodes do you think it would make sense to add this to the returns-DSL now? I am also in need of it for this exact use-case. Would also be great if there would be some way to add this in a reusable pattern.

returns(array_of: Company::ApiDescription, headers: pagy_headers)
def index
end

where we could implement pagy_headers just like a hash or even a param_group.

def pagy_headers
  [
    { key: "Link", description: "Relative links according to RFC..:"},
    { key: "Current-Page", description: "The current page in the pagination")},
    ...
  ]
end
PanosCodes commented 7 months ago

Sure, what do to you think about https://github.com/Apipie/apipie-rails/pull/924

mathieujobin commented 5 months ago

released in v1.4.0