Gets v3 request example saving as well as response example saving

Adds rubocop to the gemset

adds guard to the gemset for testing
This commit is contained in:
Jay Danielian
2019-07-05 15:59:47 -04:00
parent 5d7fc44af4
commit 297cc447c8
24 changed files with 458 additions and 261 deletions

View File

@@ -1,8 +1,9 @@
# frozen_string_literal: true
require 'rswag/specs/example_group_helpers'
module Rswag
module Specs
describe ExampleGroupHelpers do
subject { double('example_group') }
@@ -48,12 +49,12 @@ module Rswag
it "adds to the 'operation' metadata" do
expect(api_metadata[:operation]).to match(
tags: [ 'Blogs', 'Admin' ],
tags: %w[Blogs Admin],
description: 'Some description',
operationId: 'createBlog',
consumes: [ 'application/json', 'application/xml' ],
produces: [ 'application/json', 'application/xml' ],
schemes: [ 'http', 'https' ],
consumes: ['application/json', 'application/xml'],
produces: ['application/json', 'application/xml'],
schemes: %w[http https],
deprecated: true
)
end
@@ -74,27 +75,59 @@ module Rswag
it "adds to the 'operation' metadata" do
expect(api_metadata[:operation]).to match(
tags: [ 'Blogs', 'Admin' ],
tags: %w[Blogs Admin],
description: 'Some description',
operationId: 'createBlog',
consumes: [ 'application/json', 'application/xml' ],
produces: [ 'application/json', 'application/xml' ],
schemes: [ 'http', 'https' ],
consumes: ['application/json', 'application/xml'],
produces: ['application/json', 'application/xml'],
schemes: %w[http https],
deprecated: true,
security: { api_key: [] }
)
end
end
describe '#parameter(attributes)' do
describe '#request_body_json(schema)' do
let(:api_metadata) { { path_item: {}, operation: {} } } # i.e. operation defined
context 'when required is not supplied' do
before { subject.request_body_json(schema: { type: 'object' }) }
it 'adds required true by default' do
expect(api_metadata[:operation][:requestBody]).to match(
required: true, content: { 'application/json' => { schema: { type: 'object' } } }
)
end
end
context 'when required is supplied' do
before { subject.request_body_json(schema: { type: 'object' }, required: false) }
it 'adds required false' do
expect(api_metadata[:operation][:requestBody]).to match(
required: false, content: { 'application/json' => { schema: { type: 'object' } } }
)
end
end
context 'when required is supplied' do
before { subject.request_body_json(schema: { type: 'object' }, description: 'my description') }
it 'adds description' do
expect(api_metadata[:operation][:requestBody]).to match(
description: 'my description', required: true, content: { 'application/json' => { schema: { type: 'object' } } }
)
end
end
end
describe '#parameter(attributes)' do
context "when called at the 'path' level" do
before { subject.parameter(name: :blog, in: :body, schema: { type: 'object' }) }
let(:api_metadata) { { path_item: {} } } # i.e. operation not defined yet
it "adds to the 'path_item parameters' metadata" do
expect(api_metadata[:path_item][:parameters]).to match(
[ name: :blog, in: :body, schema: { type: 'object' } ]
[name: :blog, in: :body, schema: { type: 'object' }]
)
end
end
@@ -105,7 +138,7 @@ module Rswag
it "adds to the 'operation parameters' metadata" do
expect(api_metadata[:operation][:parameters]).to match(
[ name: :blog, in: :body, schema: { type: 'object' } ]
[name: :blog, in: :body, schema: { type: 'object' }]
)
end
end
@@ -116,7 +149,7 @@ module Rswag
it "automatically sets the 'required' flag" do
expect(api_metadata[:operation][:parameters]).to match(
[ name: :id, in: :path, required: true ]
[name: :id, in: :path, required: true]
)
end
end
@@ -126,7 +159,7 @@ module Rswag
let(:api_metadata) { { operation: {} } }
it "does not require the 'in' parameter key" do
expect(api_metadata[:operation][:parameters]).to match([ name: :id ])
expect(api_metadata[:operation][:parameters]).to match([name: :id])
end
end
end