Adds support for proper requestBody examples. Adds mechanism to allow for adding additional ways to add request body examples

Can add externalValue or  it will work and produce valid swagger spec.

The Symbol name matching the let parameter is always required
This commit is contained in:
Jay Danielian
2019-07-21 15:03:37 -04:00
parent 4c2097e017
commit b8dcc8fe30
7 changed files with 171 additions and 11 deletions

View File

@@ -80,6 +80,32 @@ describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do
end
end
path '/blogs/alternate' do
post 'Creates a blog - different :examples in requestBody' do
tags 'Blogs'
description 'Creates a new blog from provided data'
operationId 'createAlternateBlog'
consumes 'application/json'
produces 'application/json'
# NOTE: the externalValue: http://... is valid 3.0 spec, but swagger-UI does NOT support it yet
# https://github.com/swagger-api/swagger-ui/issues/5433
request_body_json schema: { '$ref' => '#/components/schemas/blog' },
examples: [:blog, {name: :external_blog,
externalValue: 'http://api.sample.org/myjson_example'},
{name: :another_example,
'$ref' => '#/components/examples/flexible_blog_example'}]
let(:blog) { { blog: { title: 'alt title', content: 'alt bar' } } }
response '201', 'blog created' do
schema '$ref' => '#/components/schemas/blog'
run_test!
end
end
end
path '/blogs/{id}' do

View File

@@ -69,6 +69,16 @@ RSpec.configure do |config|
required: %w[id headline]
}
},
examples: {
flexible_blog_example: {
summary: 'Sample example of a flexible blog',
value: {
id: 1,
headline: 'This is a headline',
text: 'Some sample text'
}
}
},
securitySchemes: {
basic_auth: {
type: :http,