grape-swagger
grape-swagger copied to clipboard
How to add custom headers to all apis in swagger doc
there is a way to add headers field in one api as document mentions, like below
class API::V1::Teachers < Grape::API
resource :teachers do
desc "get all teachers information" do
headers XAuthToken: {
description: 'Validates your identity',
required: true
},
XOptionalHeader: {
description: 'Not really needed',
required: false
}
end
success: API::V1::Entities::Teachers::Base
get '' do
teachers = Teacher.all
present :teachers, teachers, with: API::V1::Entities::Teachers::Base
end
end
end
but is there a way to add same headers in all apis under certain resources or namespace?
I'd be really interested to see the ability to do this
I started with a little something like this:
class API::V1::Teachers < Grape::API
resource :teachers do
desc "get all teachers information" do
headers: SWAGGER_HEADERS
end
success: API::V1::Entities::Teachers::Base
get '' do
teachers = Teacher.all
present :teachers, teachers, with: API::V1::Entities::Teachers::Base
end
end
end
SWAGGER_HEADERS = XAuthToken: {
description: 'Validates your identity',
required: true
},
XOptionalHeader: {
description: 'Not really needed',
required: false
}
ah, I see someone suggested similar in https://github.com/ruby-grape/grape/issues/2119