0

我有一些在几乎所有 API 调用中都会调用的通用参数,因此可以为这些参数创建组件并在 rswag api 请求中调用它们。

就像是schema '$ref' => '#/definitions/parameters'

谢谢!

4

2 回答 2

0

您需要在 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
end
于 2021-02-05T16:34:50.897 回答
0

添加您的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

于 2020-07-14T18:45:22.880 回答