首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何遵循json api规范使用rswag创建?

如何遵循json api规范使用rswag创建?
EN

Stack Overflow用户
提问于 2019-11-18 06:24:48
回答 1查看 1.5K关注 0票数 5

我没有找到任何关于如何使用rswag根据json api生成文档的示例。

spec/integration/pets_spec.rb

需要“swagger_helper”

可以更改代码来生成json api的格式吗?

代码语言:javascript
复制
describe 'Pets API' do

  path '/api/v1/pets' do

    post 'Creates a pet' do
      tags 'Pets'
      consumes 'application/json', 'application/xml'
      parameter name: :pet, in: :body, schema: {
        type: :object,
        properties: {
          name: { type: :string },
          photo_url: { type: :string },
          status: { type: :string }
        },
        required: [ 'name', 'status' ]
      }

      response '201', 'pet created' do
        let(:pet) { { name: 'Dodo', status: 'available' } }
        run_test!
      end

      response '422', 'invalid request' do
        let(:pet) { { name: 'foo' } }
        run_test!
      end
    end
  end

  path '/api/v1/pets/{id}' do

    get 'Retrieves a pet' do
      tags 'Pets'
      produces 'application/json', 'application/xml'
      parameter name: :id, :in => :path, :type => :string

      response '200', 'name found' do
        schema type: :object,
          properties: {
            id: { type: :integer, },
            name: { type: :string },
            photo_url: { type: :string },
            status: { type: :string }
          },
          required: [ 'id', 'name', 'status' ]

        let(:id) { Pet.create(name: 'foo', status: 'bar', photo_url: 'http://example.com/avatar.jpg').id }
        run_test!
      end

      response '404', 'pet not found' do
        let(:id) { 'invalid' }
        run_test!
      end
    end
  end
end

如果是rswag,你会给我什么建议?

EN

回答 1

Stack Overflow用户

发布于 2020-03-21 06:51:54

您需要更改swagger_helper.rb文件。将文件格式更改为JSON。我已经附上了下面的截图:

https://i.stack.imgur.com/MzOR9.png

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58905791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档