Ruby on rails 如何按照json api规范使用rswag创建?
我没有找到任何关于如何使用rswag根据jsonapi生成文档的示例 规范/集成/pets\U规范rb 需要“大摇大摆的助手” 是否可以更改代码以生成json api的格式Ruby on rails 如何按照json api规范使用rswag创建?,ruby-on-rails,api,swagger,rswag,Ruby On Rails,Api,Swagger,Rswag,我没有找到任何关于如何使用rswag根据jsonapi生成文档的示例 规范/集成/pets\U规范rb 需要“大摇大摆的助手” 是否可以更改代码以生成json api的格式 describe 'Pets API' do path '/api/v1/pets' do post 'Creates a pet' do tags 'Pets' consumes 'application/json', 'application/xml' paramete
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,您会给我什么提示?您需要更改
swagger\u helper.rb
文件。将文件格式更改为JSON。我已经附上了下面的截图:
这可能是一个误解:问题在于测试+记录和遵循此处找到的json.API规范的API,而不是swagger.yml或swagger.json文件