Ruby on rails rswag gem:响应块中模式的主要用途是什么?

Ruby on rails rswag gem:响应块中模式的主要用途是什么?,ruby-on-rails,rspec,ruby-on-rails-5,rswag,Ruby On Rails,Rspec,Ruby On Rails 5,Rswag,上面代码中的关键字模式对我们有什么好处? 真正的反应与此相比吗?如果不匹配,则引发错误?是,rswag将验证您的API响应是否与运行测试时指定的模式匹配。它还将在生成的swagger文档中将模式作为“模型”输出 在您给出的示例中,它将在config.swagger\u文档中查找errors\u对象。rswag文档向您展示了如何定义它: describe 'Blogs API' do path '/blogs' do post 'Creates a blog' do

上面代码中的关键字模式对我们有什么好处?
真正的反应与此相比吗?如果不匹配,则引发错误?

是,rswag将验证您的API响应是否与运行测试时指定的模式匹配。它还将在生成的swagger文档中将模式作为“模型”输出

在您给出的示例中,它将在
config.swagger\u文档中查找
errors\u对象
。rswag文档向您展示了如何定义它:

describe 'Blogs API' do

  path '/blogs' do

    post 'Creates a blog' do

      response 422, 'invalid request' do
        **schema** '$ref' => '#/definitions/errors_object'
  ...
end

不确定您在这里要问什么,因为该代码会引发语法错误。
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' }
        }
      }
    }
  }
}