英文:
Multiple dock in one project with rswag rails
问题
我尝试为我的API创建2个文档。我的路由中有2个命名空间,我需要为第一个命名空间和第二个命名空间创建2个文档。在请求测试中,它们分为2个文件夹。如何自动生成这2个文档,以及我需要在路由文件中编写什么?
在路由文件中,我为rswag引擎写了2个挂载点,但我不知道我需要对我的swagger.yml文件做什么。
英文:
I try to create 2 docs for my api. I have 2 namespaces in routes and I need to create 2 docs for my first namespace and second namespace. In request test they are divided on 2 folders. How can I automatically generate this 2 docs and what i need to write in routes file?
In routes I wrote 2 mounts for rswag engine, but I don't not what I need to do with my swagger.yml file
答案1
得分: 0
以下是您要翻译的内容:
Some time later I managed it something like this:
swagger_helper.rb:
docs = { 'v1/robots_api.yaml' => {
openapi: '3.0.1',
info: {
title: 'API V1',
version: 'v1'
},
paths: {},
components: {
securitySchemes: {
Bearer: {
description: 'JWT key necessary to use API calls',
type: :apiKey,
name: 'Authorization',
in: :header
}
}
},
servers: [
{
url: ENV.fetch('ROUTES_HOST'),
variables: {
defaultHost: {
default: ENV.fetch('ROUTES_HOST')
}
}
}
] }
if Rails.env.development?
docs.merge!({ 'v1/swagger.yaml' => {
openapi: '3.0.1',
info: {
title: 'API V1',
version: 'v1'
},
paths: {},
components: {
securitySchemes: {
Bearer: {
description: 'JWT key necessary to use API calls',
type: :apiKey,
name: 'Authorization',
in: :header
}
}
},
servers: [
{
url: ENV.fetch('ROUTES_HOST'),
variables: {
defaultHost: {
default: ENV.fetch('ROUTES_HOST')
}
}
}
] })
end
config.swagger_docs = docs
config/initialaziers/rswag_ui.rb
Rswag::Ui.configure do |c|
c.swagger_endpoint '/api-docs/v1/swagger.yaml', 'API V1 Docs' if Rails.env.development?
c.swagger_endpoint '/<api_name>/api-docs/v1/<my_second_doc>.yaml', 'API V1 Docs <my api>'
end
And then I use rake rswag it generates for me 2 docs.
请注意,代码部分未被翻译。
英文:
Some time later I managed it something like this:
swagger_helper.rb:
docs = { 'v1/robots_api.yaml' => {
openapi: '3.0.1',
info: {
title: 'API V1',
version: 'v1'
},
paths: {},
components: {
securitySchemes: {
Bearer: {
description: 'JWT key necessary to use API calls',
type: :apiKey,
name: 'Authorization',
in: :header
}
}
},
servers: [
{
url: ENV.fetch('ROUTES_HOST'),
variables: {
defaultHost: {
default: ENV.fetch('ROUTES_HOST')
}
}
}
]
} }
if Rails.env.development?
docs.merge!({ 'v1/swagger.yaml' => {
openapi: '3.0.1',
info: {
title: 'API V1',
version: 'v1'
},
paths: {},
components: {
securitySchemes: {
Bearer: {
description: 'JWT key necessary to use API calls',
type: :apiKey,
name: 'Authorization',
in: :header
}
}
},
servers: [
{
url: ENV.fetch('ROUTES_HOST'),
variables: {
defaultHost: {
default: ENV.fetch('ROUTES_HOST')
}
}
}
]
} })
end
config.swagger_docs = docs
config/initialaziers/rswag_ui.rb
Rswag::Ui.configure do |c|
c.swagger_endpoint '/api-docs/v1/swagger.yaml', 'API V1 Docs' if Rails.env.development?
c.swagger_endpoint '/<api_name>/api-docs/v1/<my_second_doc>.yaml', 'API V1 Docs <my api>'
end
And then I use rake rswag it generates for me 2 docs.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论