我有一些公共参数,这些参数在几乎所有的API调用中都会被调用,所以是否可以为这些参数创建组件并在rswag请求中调用它们。
像schema '$ref' => '#/definitions/parameters'这样的东西
谢谢!
发布于 2020-07-15 02:45:23
添加到您的swagger_helper.rb中
示例:
# spec/swagger_helper.rb
config.swagger_docs = {
'v1/swagger.json' => {
swagger: '2.0',
info: {
title: 'API V1'
},
definitions: {
errors_object: {
type: 'object',
properties: {
errors: { '$ref' => '#/definitions/errors_map' }
}
},
errors_map: {
type: 'object',
additionalProperties: {
type: 'array',
items: { type: 'string' }
}
}
}
}
}
# spec/integration/blogs_spec.rb
describe 'Blogs API' do
path '/blogs' do
post 'Creates a blog' do
response 422, 'invalid request' do
schema '$ref' => '#/definitions/errors_object'
...
end
# spec/integration/comments_spec.rb
describe 'Blogs API' do
path '/blogs/{blog_id}/comments' do
post 'Creates a comment' do
response 422, 'invalid request' do
schema '$ref' => '#/definitions/errors_object'
...
end来自:https://www.rubydoc.info/github/domaindrivendev/rswag#referenced-parameters-and-schema-definitions
发布于 2021-02-06 00:34:51
您需要在spec/swagger_helper.rb中定义对象,然后在集成规范文件中定义
path '/api/client/v0/blog' do
put 'Create a blog' do
tags :Blog
include_examples 'header_with_recognition_definitions'
parameter name: :input_param, in: :body, schema: { '$ref' => '#/definitions/input_parameter_object' }
response 200, 'blog was created successfully' do
include_examples 'header_with_recognition_lets'
...
run_test!
end
endhttps://stackoverflow.com/questions/60280341
复制相似问题