Apipie / apipie-rails

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

Custom headers responses #924

Closed PanosCodes closed 4 months ago

PanosCodes commented 6 months ago

Why

To define custom response headers https://github.com/Apipie/apipie-rails/issues/706

How

Extend the Apipie::ResponseDescription::ResponseObject with a header method

Example

api :GET, "/pets/:id/with-extra-details", "Get a detailed pet record"
returns code: 200, desc: "Detailed info about the pet" do
  param_group :pet
  property :num_legs, Integer, :desc => "How many legs the pet has"
  header 'Link', String, 'Relative links'
  header 'Current-Page', Integer, 'The current page', required: true
end

def show
  render JSON({ :pet_name => "Barkie", :animal_type => "iguana", :legs => 4 })
end
davidwessman commented 6 months ago

Is there anyway to use array_of: DescriptionObject that uses the https://github.com/Apipie/apipie-rails?tab=readme-ov-file#embedded-response-descriptions inside the returns block?

PanosCodes commented 6 months ago

You can delete this line 😅 https://github.com/Apipie/apipie-rails/blob/f300fcc27c7805bcce54b6e02d147bd15931ab12/lib/apipie/dsl_definition.rb#L436.

I'm not sure why it exists, there are no failing tests if it's removed 🤔

davidwessman commented 6 months ago

You can delete this line 😅

https://github.com/Apipie/apipie-rails/blob/f300fcc27c7805bcce54b6e02d147bd15931ab12/lib/apipie/dsl_definition.rb#L436

. I'm not sure why it exists, there are no failing tests if it's removed 🤔

Hehe, that would be nice!

davidwessman commented 4 months ago

@mathieujobin Any chance to get this merged?

mathieujobin commented 4 months ago

Sorry for the delay here

davidwessman commented 4 months ago

No worries, thank you!