Merge branch 'openapi/master' into openapi/merge

This commit is contained in:
Greg Myers
2020-03-20 15:38:40 +00:00
42 changed files with 1296 additions and 346 deletions

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rswag/specs/configuration'
module Rswag

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rswag/specs/example_group_helpers'
module Rswag
@@ -86,6 +88,40 @@ module Rswag
end
end
## OA3
# 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
@@ -147,6 +183,8 @@ module Rswag
it "adds to the 'response' metadata" do
expect(api_metadata[:response][:schema]).to match(type: 'object')
## OA3
# expect(api_metadata[:response][:content]['application/json'][:schema]).to match(type: 'object')
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rswag/specs/example_helpers'
module Rswag
@@ -24,6 +26,21 @@ module Rswag
}
}
end
## OA3
# let(:swagger_doc) do
# {
# components: {
# securitySchemes: {
# api_key: {
# type: :apiKey,
# name: 'api_key',
# in: :query
# }
# }
# }
# }
# end
let(:metadata) do
{
path_item: { template: '/blogs/{blog_id}/comments/{id}' },
@@ -58,8 +75,10 @@ module Rswag
it "submits a request built from metadata and 'let' values" do
expect(subject).to have_received(:put).with(
'/blogs/1/comments/2?q1=foo&api_key=fookey',
"{\"text\":\"Some comment\"}",
'{"text":"Some comment"}',
{ 'CONTENT_TYPE' => 'application/json' }
## OA3
# 'CONTENT_TYPE' => 'application/json'
)
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rswag/specs/request_factory'
module Rswag
@@ -204,6 +206,8 @@ module Rswag
context 'basic auth' do
before do
swagger_doc[:securityDefinitions] = { basic: { type: :basic } }
## OA3
# swagger_doc[:components] = { securitySchemes: { basic: { type: :basic } } }
metadata[:operation][:security] = [ basic: [] ]
allow(example).to receive(:Authorization).and_return('Basic foobar')
end
@@ -216,6 +220,10 @@ module Rswag
context 'apiKey' do
before do
swagger_doc[:securityDefinitions] = { apiKey: { type: :apiKey, name: 'api_key', in: key_location } }
## OA3
# swagger_doc[:components] = { securitySchemes: {
# apiKey: { type: :apiKey, name: 'api_key', in: key_location }
# } }
metadata[:operation][:security] = [ apiKey: [] ]
allow(example).to receive(:api_key).and_return('foobar')
end
@@ -257,6 +265,10 @@ module Rswag
context 'oauth2' do
before do
swagger_doc[:securityDefinitions] = { oauth2: { type: :oauth2, scopes: [ 'read:blogs' ] } }
## OA3
# swagger_doc[:components] = { securitySchemes: {
# oauth2: { type: :oauth2, scopes: ['read:blogs'] }
# } }
metadata[:operation][:security] = [ oauth2: [ 'read:blogs' ] ]
allow(example).to receive(:Authorization).and_return('Bearer foobar')
end
@@ -272,6 +284,11 @@ module Rswag
basic: { type: :basic },
api_key: { type: :apiKey, name: 'api_key', in: :query }
}
## OA3
# swagger_doc[:components] = { securitySchemes: {
# basic: { type: :basic },
# api_key: { type: :apiKey, name: 'api_key', in: :query }
# } }
metadata[:operation][:security] = [ { basic: [], api_key: [] } ]
allow(example).to receive(:Authorization).and_return('Basic foobar')
allow(example).to receive(:api_key).and_return('foobar')
@@ -327,6 +344,8 @@ module Rswag
context "global security requirements" do
before do
swagger_doc[:securityDefinitions] = { apiKey: { type: :apiKey, name: 'api_key', in: :query } }
## OA3
# swagger_doc[:components] = { securitySchemes: { apiKey: { type: :apiKey, name: 'api_key', in: :query } } }
swagger_doc[:security] = [ apiKey: [] ]
allow(example).to receive(:api_key).and_return('foobar')
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rswag/specs/response_validator'
module Rswag
@@ -22,6 +24,16 @@ module Rswag
properties: { text: { type: :string } },
required: [ 'text' ]
}
## OA3
# content: {
# 'application/json' => {
# schema: {
# type: :object,
# properties: { text: { type: :string } },
# required: ['text']
# }
# }
# }
}
}
end
@@ -65,6 +77,16 @@ module Rswag
}
}
metadata[:response][:schema] = { '$ref' => '#/definitions/blog' }
## OA3
# swagger_doc[:components] = {}
# swagger_doc[:components][:schemas] = {
# 'blog' => {
# type: :object,
# properties: { foo: { type: :string } },
# required: ['foo']
# }
# }
# metadata[:response][:content]['application/json'][:schema] = { '$ref' => '#/components/schemas/blog' }
end
it 'uses the referenced schema to validate the response body' do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rswag/specs/swagger_formatter'
require 'ostruct'