如何解决RSpec swaggerOpenAPI 3错误:模式上不存在'/ components / responses'
使用gem rswag-specs(2.3.1)。根据{{3}}在responses
中定义了components
:
config.swagger_docs = {
'swagger.yaml' => {
openapi: '3.0.1',info: {
title: 'title',},paths: {},components: {
responses: {
"403": {
type: :object,properties: {
errors: {
type: :array,items: {
'$ref' => '#/components/schemas/forbidden_error'
}
}
}
}
}
}
}
}
测试失败并显示错误:
response '403','Wrong permissions' do
let(:Authorization) { "Bearer #{token}" }
let(:id) { item.id }
schema '$ref' => '#/components/responses/403'
run_test!
end
JSON::Schema::SchemaError:
The fragment '/components/responses' does not exist on schema aec776a1-291e-5317-89bf-6ea163b4bac3
如何使用/ components / responses部分?
解决方法
更新
我未定义示例'#/components/schemas/forbidden_error'
。尝试将其添加到/components/schemas
或内联它,如"404"
示例。
config.swagger_docs = {
'swagger.yaml' => {
openapi: '3.0.1',info: {
title: 'title',},paths: {},components: {
schemas: {
forbidden_error: {
type: object,properties: {
message: string
}
}
},responses: {
"403": {
type: :object,properties: {
errors: {
type: :array,items: {
'$ref' => '#/components/schemas/forbidden_error'
}
}
}
},"404": {
type: :object,items: {
type: object,properties: {
message: string
}
}
}
}
}
}
}
}
}
原始答案
这是错误的方法。
the rswag gem readme中的示例表明嵌套为 components/schemas/refrenced_object
。在您的示例中,responses
直接位于components
下。也会将responses
移至“方案”下。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。