mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 07:16:40 +00:00
Fixes response_validator to handle 3.0 responses and validate against the schema.
JSON::Validator already handles anyOf oneOf schema definitions, so those can be passed in and validation errors are returned properly
This commit is contained in:
@@ -15,7 +15,6 @@ class BlogsController < ApplicationController
|
||||
# request body definition for 3.0
|
||||
blog_params = params.require(:blog).permit(:title, :content, :headline, :text)
|
||||
|
||||
|
||||
@blog = Blog.create(blog_params)
|
||||
respond_with @blog
|
||||
end
|
||||
|
||||
@@ -74,7 +74,7 @@ describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do
|
||||
let(:flexible_blog) { { blog: { headline: 'my headline', text: 'my text' } } }
|
||||
|
||||
response '201', 'flexible blog created' do
|
||||
schema '$ref' => '#/components/schemas/blog'
|
||||
schema :oneOf => [{'$ref' => '#/components/schemas/blog'},{'$ref' => '#/components/schemas/flexible_blog'}]
|
||||
run_test!
|
||||
end
|
||||
end
|
||||
@@ -120,7 +120,7 @@ describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
path '/blogs/{id}/upload' do
|
||||
let(:id) { blog.id }
|
||||
let(:blog) { Blog.create(title: 'foo', content: 'bar') }
|
||||
|
||||
@@ -54,9 +54,9 @@ RSpec.configure do |config|
|
||||
id: { type: 'integer' },
|
||||
title: { type: 'string' },
|
||||
content: { type: 'string', nullable: true },
|
||||
thumbnail: { type: 'string' }
|
||||
thumbnail: { type: 'string', nullable: true }
|
||||
},
|
||||
required: %w[id title content thumbnail]
|
||||
required: %w[id title]
|
||||
},
|
||||
flexible_blog: {
|
||||
type: 'object',
|
||||
@@ -64,9 +64,9 @@ RSpec.configure do |config|
|
||||
id: { type: 'integer' },
|
||||
headline: { type: 'string' },
|
||||
text: { type: 'string', nullable: true },
|
||||
thumbnail: { type: 'string' }
|
||||
thumbnail: { type: 'string', nullable:true }
|
||||
},
|
||||
required: %w[id headline thumbnail]
|
||||
required: %w[id headline]
|
||||
}
|
||||
},
|
||||
securitySchemes: {
|
||||
|
||||
@@ -243,7 +243,14 @@
|
||||
"thumbnail": null
|
||||
},
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/blog"
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/blog"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/flexible_blog"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -395,14 +402,13 @@
|
||||
"nullable": true
|
||||
},
|
||||
"thumbnail": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"title",
|
||||
"content",
|
||||
"thumbnail"
|
||||
"title"
|
||||
]
|
||||
},
|
||||
"flexible_blog": {
|
||||
@@ -419,13 +425,13 @@
|
||||
"nullable": true
|
||||
},
|
||||
"thumbnail": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"headline",
|
||||
"thumbnail"
|
||||
"headline"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user