Ruby on rails Grape API(swagger doc)';描述';
这是一个有趣的忙碌的一周。我正在从事一个Rails项目,其中包括Ruby on rails Grape API(swagger doc)';描述';,ruby-on-rails,api,documentation,swagger,grape,Ruby On Rails,Api,Documentation,Swagger,Grape,这是一个有趣的忙碌的一周。我正在从事一个Rails项目,其中包括Grape以实现API API有两个部分 无需身份验证(无标题) 需要身份验证 我安装了应用程序,所有的都在工作 葡萄 葡萄招摇 葡萄招摇过市轨道 为了说明需要一个标题,我使用了这样的东西 class ProfilesApi < Grape::API resource :profiles do desc 'List all profiles' do headers Authorization
Grape
以实现API
API有两个部分
- 无需身份验证(无标题)
- 需要身份验证
- 葡萄
- 葡萄招摇
- 葡萄招摇过市轨道
class ProfilesApi < Grape::API
resource :profiles do
desc 'List all profiles' do
headers Authorization: {
description: 'Validates identity through JWT provided in auth/login',
required: true
}
end
get do
present User.all, with: Presenters::ProfilePresenter
end
end
end
提前谢谢,希望你们周末过得愉快。是的,有办法。我通过在
类API
中定义一个方法来实现这一点,以便在继承自API
的所有内容中都可以访问它。比如:
module Myapp
class API < Grape::API
def self.auth_headers
{ Authorization: { description: 'Validates identity through JWT provided in auth/login',required: true}}
end
end
end
当然,有更多的方法,但它们取决于您的实现。我认为这可能是grape api的更新版本,我必须使用以下方法:
desc 'My description text' do
headers Authorization: {description: "pass the access token as Bearer", required: true }
end
desc "List all profiles", {
headers: Myapp::API.auth_headers
}
desc 'My description text' do
headers Authorization: {description: "pass the access token as Bearer", required: true }
end