我想按照 json api 规范创建一个带有 swagger 和 rails 的文档。
我的代码:
require 'swagger_helper'
describe 'Blogs API' do
path '/blogs' do
post 'Creates a blog' do
tags 'Blogs'
consumes 'application/json', 'application/xml'
parameter name: :blog, in: :body, schema: {
properties: {
data: {
type: :object,
items: {
properties: {
title: { type: :string },
content: { type: :string }
},
required: ['data','title']
}
},
},
}
response '201', 'blog created' do
let(:blog) { { title: 'foo', content: 'bar' } }
run_test!
end
response '422', 'invalid request' do
let(:blog) { { title: 'foo' } }
run_test!
end
end
end
end
我想在下面为 json 创建代码:
data: {
type: articles,
attributes: {
title: { type: :string },
content: { type: :string }
},
}
我如何在 rswag 中执行此操作,在 json api 规范中是否有任何技巧?