2

我已经成功地使用rspec_api_documentationgem 为应用程序中的一些其他资源生成文档。

但是当我对新资源执行相同操作时,JSON 文件response_body是空的(尽管 JSON 的其余部分存在)。我不确定为什么会这样。

生成的 JSON 中的 response_body:

"response_body": "{\n  \"data\": {\n    \"notes\": [\n\n    ]\n  },\n  \"status\": 200,\n  \"message\": \"Ok\"\n}"

输出的 API 文档:

{
  "data": {
    "notes": [

    ]
  },
  "status": 200,
  "message": "Ok"
}

我做了什么:

  • 用 a 测试了端点curl并可以确认它返回完整的响应(现在我只是在尝试构建文档)
  • 已创建note_factory.rb
  • 在开头的块中@notes = create_list(:note, 1,...)添加(并打印到控制台以确认它创建了一个对象)before(:all) donotes_spec.rb

也在下面创建作为测试。

get '/api/v1/notes' do

  example 'Return all notes' do
    explanation 'Return all notes within an account.'

    set_jwt_auth_headers(@api_reader)

    do_request

    expect(status).to eq 200
  end
end

我很困惑我可能会丢失什么导致相关的 JSON 响应RAD为空。

有没有人有任何想法可能导致这种情况?

4

0 回答 0