如何使用grape Swagger将外部API文档添加到Swagger中?
如何添加外部API文档 例如,我使用门卫,如何使用grape Swagger将外部API文档添加到Swagger中?,swagger,grape,grape-api,Swagger,Grape,Grape Api,如何添加外部API文档 例如,我使用门卫,POST/api/v1/token 那不是一个好主意。如何将此端点添加到swagger中?我今天面临同样的问题。我使用Grape作为API,并使用Doorkeeper作为OAuth 2提供者。Doorkeeper提供了几个API端点,例如POST/oauth/authorize,POST/oauth/token 我将一个虚拟的oauthapi类添加到我的api中,使用desc和params描述每个端点。当然,我必须手动列出所有参数(必需或可选、名称、类型
POST/api/v1/token
那不是一个好主意。如何将此端点添加到swagger中?我今天面临同样的问题。我使用Grape作为API,并使用Doorkeeper作为OAuth 2提供者。Doorkeeper提供了几个API端点,例如
POST/oauth/authorize
,POST/oauth/token
我将一个虚拟的oauth
api类添加到我的api中,使用desc
和params
描述每个端点。当然,我必须手动列出所有参数(必需或可选、名称、类型、描述、值等)。但我将实现留空。当用户调用这些API时,请求将被路由到Doorkeeper以执行实际操作
例如,我的代码关于POST/oauth/token
endpoint:
module API
class Oauth < Grape::API
resources :oauth do
# POST /oauth/token
desc 'Requires for an access token'
params do
requires :grant_type,
type: String,
values: %w(client_credentials authorization_code)
optional :code,
type: String
requires :client_id,
type: String
requires :client_secret,
type: String
optional :redirect_uri,
type: String,
default: 'urn:ietf:wg:oauth:2.0:oob'
end
post :token do
end
end # resources :oauth
add_swagger_documentation mount_path: 'oauth/swagger_doc',
api_version: '',
format: :json,
hide_format: true,
hide_documentation_path: true
end
end
模块API
类Oauth
以及生成的招摇过市文档:
我今天也面临同样的问题。我使用Grape作为API,并使用Doorkeeper作为OAuth 2提供者。Doorkeeper提供了几个API端点,例如
POST/oauth/authorize
,POST/oauth/token
我将一个虚拟的oauth
api类添加到我的api中,使用desc
和params
描述每个端点。当然,我必须手动列出所有参数(必需或可选、名称、类型、描述、值等)。但我将实现留空。当用户调用这些API时,请求将被路由到Doorkeeper以执行实际操作
例如,我的代码关于POST/oauth/token
endpoint:
module API
class Oauth < Grape::API
resources :oauth do
# POST /oauth/token
desc 'Requires for an access token'
params do
requires :grant_type,
type: String,
values: %w(client_credentials authorization_code)
optional :code,
type: String
requires :client_id,
type: String
requires :client_secret,
type: String
optional :redirect_uri,
type: String,
default: 'urn:ietf:wg:oauth:2.0:oob'
end
post :token do
end
end # resources :oauth
add_swagger_documentation mount_path: 'oauth/swagger_doc',
api_version: '',
format: :json,
hide_format: true,
hide_documentation_path: true
end
end
模块API
类Oauth
以及生成的招摇过市文档:
我今天也面临同样的问题。我使用Grape作为API,并使用Doorkeeper作为OAuth 2提供者。Doorkeeper提供了几个API端点,例如
POST/oauth/authorize
,POST/oauth/token
我将一个虚拟的oauth
api类添加到我的api中,使用desc
和params
描述每个端点。当然,我必须手动列出所有参数(必需或可选、名称、类型、描述、值等)。但我将实现留空。当用户调用这些API时,请求将被路由到Doorkeeper以执行实际操作
例如,我的代码关于POST/oauth/token
endpoint:
module API
class Oauth < Grape::API
resources :oauth do
# POST /oauth/token
desc 'Requires for an access token'
params do
requires :grant_type,
type: String,
values: %w(client_credentials authorization_code)
optional :code,
type: String
requires :client_id,
type: String
requires :client_secret,
type: String
optional :redirect_uri,
type: String,
default: 'urn:ietf:wg:oauth:2.0:oob'
end
post :token do
end
end # resources :oauth
add_swagger_documentation mount_path: 'oauth/swagger_doc',
api_version: '',
format: :json,
hide_format: true,
hide_documentation_path: true
end
end
模块API
类Oauth
以及生成的招摇过市文档:
我今天也面临同样的问题。我使用Grape作为API,并使用Doorkeeper作为OAuth 2提供者。Doorkeeper提供了几个API端点,例如
POST/oauth/authorize
,POST/oauth/token
我将一个虚拟的oauth
api类添加到我的api中,使用desc
和params
描述每个端点。当然,我必须手动列出所有参数(必需或可选、名称、类型、描述、值等)。但我将实现留空。当用户调用这些API时,请求将被路由到Doorkeeper以执行实际操作
例如,我的代码关于POST/oauth/token
endpoint:
module API
class Oauth < Grape::API
resources :oauth do
# POST /oauth/token
desc 'Requires for an access token'
params do
requires :grant_type,
type: String,
values: %w(client_credentials authorization_code)
optional :code,
type: String
requires :client_id,
type: String
requires :client_secret,
type: String
optional :redirect_uri,
type: String,
default: 'urn:ietf:wg:oauth:2.0:oob'
end
post :token do
end
end # resources :oauth
add_swagger_documentation mount_path: 'oauth/swagger_doc',
api_version: '',
format: :json,
hide_format: true,
hide_documentation_path: true
end
end
模块API
类Oauth