Ruby on rails 在Rails中使用rswag-索引响应(数组)的语法是什么?

Ruby on rails 在Rails中使用rswag-索引响应(数组)的语法是什么?,ruby-on-rails,ruby,swagger,rswag,Ruby On Rails,Ruby,Swagger,Rswag,不幸的是,rswag的“文档”似乎非常缺乏,并且没有给出如何实现索引操作的示例。我的“create”规范在Swagger用户界面中显示模式和示例值,但我的“index”方法在用户界面中都不显示 我需要在这里换什么?我已经根据我找到的有限的例子对它进行了研究,但它们似乎都不起作用 path '/api/v1/users' do get('list users') do tags 'Users' response(200, 'successful') do schema type

不幸的是,rswag的“文档”似乎非常缺乏,并且没有给出如何实现索引操作的示例。我的“create”规范在Swagger用户界面中显示模式和示例值,但我的“index”方法在用户界面中都不显示

我需要在这里换什么?我已经根据我找到的有限的例子对它进行了研究,但它们似乎都不起作用

path '/api/v1/users' do

get('list users') do
  tags 'Users'

  response(200, 'successful') do
    schema type: :array,
           properties: {
             id: { type: :integer },
             title: { type: :string },
             created_at: { type: :datetime},
             updated_at: { type: :datetime}
           }
    after do |example|
      example.metadata[:response][:content] = {
        'application/json' => {
          example: JSON.parse(response.body, symbolize_names: true)
        }
      }
    end
    run_test!
  end
end

post('create user') do
  tags 'Users'
  consumes 'application/json'
  parameter name: :user, in: :body, schema: {
    type: :object,
    properties: {
      title: { type: :string }
    },
  required: [ 'title', 'description' ]
}
  response(200, 'successful') do

    after do |example|
      example.metadata[:response][:content] = {
        'application/json' => {
          example: JSON.parse(response.body, symbolize_names: true)
        }
      }
    end
    run_test!
  end
end
end
我还根据我发现的另一个示例,尝试将模式格式化为这样,但也没有做任何事情(模式/示例只是没有显示):-


检查您的
swagger\u助手
文件。如果您遵循了文档,可能是这样的:

RSpec.configure do |config|
  config.swagger_root = Rails.root.to_s + '/swagger'

  config.swagger_docs = {
    'v1/swagger.json' => {
      openapi: '3.0.1',
      info: {
        title: 'API V1',
        version: 'v1',
        description: 'This is the first version of my API'
      },
      servers: [
        {
          url: 'https://{defaultHost}',
          variables: {
            defaultHost: {
                default: 'www.example.com'
            }
          }
        }
      ]
    }
  }
end

只需将
opeanapi:'3.0.1'
替换为
swagger:'2.0'
。我也遇到过同样的问题,这是迄今为止我找到的唯一解决办法。

非常感谢@João-这非常有效。好奇的是,你从哪里找到答案的?我在他们的文档中没有找到太多的信息。他们的文档确实缺少很多信息。我不是从那里得到的,tho。我注意到我生成的文档与swagger提供的宠物店示例之间的差异:奇怪的是,这是因为最近对rswag库做了一些更改。在我更新它之前,我使用它没有任何问题。
RSpec.configure do |config|
  config.swagger_root = Rails.root.to_s + '/swagger'

  config.swagger_docs = {
    'v1/swagger.json' => {
      openapi: '3.0.1',
      info: {
        title: 'API V1',
        version: 'v1',
        description: 'This is the first version of my API'
      },
      servers: [
        {
          url: 'https://{defaultHost}',
          variables: {
            defaultHost: {
                default: 'www.example.com'
            }
          }
        }
      ]
    }
  }
end