diff --git a/rswag-specs/lib/rswag/specs/example_group_helpers.rb b/rswag-specs/lib/rswag/specs/example_group_helpers.rb index 27bd2db..a54344e 100644 --- a/rswag-specs/lib/rswag/specs/example_group_helpers.rb +++ b/rswag-specs/lib/rswag/specs/example_group_helpers.rb @@ -43,7 +43,9 @@ module Rswag # TODO: setup travis CI? # MUST HAVES - # TODO: look at integrating and documenting the rest of the responses in the blog_spec and get a clean 3.0 output + # TODO: fix the specs in the rswag-specs gem + # TODO: look at handling different ways schemas can be defined in 3.0 for requestBody and response + # can we handle all of them? # Then can look at handling different request_body things like $ref, etc # TODO: look at adding request_body method to handle diffs in Open API 2.0 to 3.0 # TODO: look at adding examples in content request_body diff --git a/rswag-specs/lib/rswag/specs/request_factory.rb b/rswag-specs/lib/rswag/specs/request_factory.rb index 31f1831..adc673c 100644 --- a/rswag-specs/lib/rswag/specs/request_factory.rb +++ b/rswag-specs/lib/rswag/specs/request_factory.rb @@ -40,7 +40,8 @@ module Rswag def derive_security_params(metadata, swagger_doc) requirements = metadata[:operation][:security] || swagger_doc[:security] || [] scheme_names = requirements.flat_map(&:keys) - schemes = (swagger_doc[:components][:securitySchemes] || {}).slice(*scheme_names).values + components = swagger_doc[:components] || {} + schemes = (components[:securitySchemes] || {}).slice(*scheme_names).values schemes.map do |scheme| param = scheme[:type] == :apiKey ? scheme.slice(:name, :in) : { name: 'Authorization', in: :header } diff --git a/rswag-specs/lib/rswag/specs/response_validator.rb b/rswag-specs/lib/rswag/specs/response_validator.rb index b5e4a8c..4f14829 100644 --- a/rswag-specs/lib/rswag/specs/response_validator.rb +++ b/rswag-specs/lib/rswag/specs/response_validator.rb @@ -42,7 +42,8 @@ module Rswag response_schema = metadata[:response][:schema] return if response_schema.nil? - components_schemas = { components: { schemas: swagger_doc[:components][:schemas] } } + components = swagger_doc[:components] || {} + components_schemas = { components: { schemas: components[:schemas] } } validation_schema = response_schema .merge('$schema' => 'http://tempuri.org/rswag/specs/extended_schema') diff --git a/rswag-specs/spec/rswag/specs/example_helpers_spec.rb b/rswag-specs/spec/rswag/specs/example_helpers_spec.rb index 01da373..3c51633 100644 --- a/rswag-specs/spec/rswag/specs/example_helpers_spec.rb +++ b/rswag-specs/spec/rswag/specs/example_helpers_spec.rb @@ -16,11 +16,13 @@ module Rswag let(:config) { double('config') } let(:swagger_doc) do { - securityDefinitions: { - api_key: { - type: :apiKey, - name: 'api_key', - in: :query + components: { + securitySchemes: { + api_key: { + type: :apiKey, + name: 'api_key', + in: :query + } } } } diff --git a/rswag-specs/spec/rswag/specs/request_factory_spec.rb b/rswag-specs/spec/rswag/specs/request_factory_spec.rb index 7651811..c2cabb9 100644 --- a/rswag-specs/spec/rswag/specs/request_factory_spec.rb +++ b/rswag-specs/spec/rswag/specs/request_factory_spec.rb @@ -204,7 +204,10 @@ module Rswag context 'basic auth' do before do - swagger_doc[:securityDefinitions] = { basic: { type: :basic } } + swagger_doc[:components] = { securitySchemes: { + basic: { type: :basic } + } + } metadata[:operation][:security] = [basic: []] allow(example).to receive(:Authorization).and_return('Basic foobar') end @@ -216,7 +219,10 @@ module Rswag context 'apiKey' do before do - swagger_doc[:securityDefinitions] = { apiKey: { type: :apiKey, name: 'api_key', in: key_location } } + 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,7 +263,10 @@ module Rswag context 'oauth2' do before do - swagger_doc[:securityDefinitions] = { oauth2: { type: :oauth2, scopes: ['read:blogs'] } } + 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 @@ -269,9 +278,10 @@ module Rswag context 'paired security requirements' do before do - swagger_doc[:securityDefinitions] = { - basic: { type: :basic }, - api_key: { type: :apiKey, name: 'api_key', in: :query } + 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') @@ -327,7 +337,7 @@ module Rswag context 'global security requirements' do before do - swagger_doc[:securityDefinitions] = { apiKey: { type: :apiKey, name: 'api_key', in: :query } } + 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 diff --git a/rswag-specs/spec/rswag/specs/response_validator_spec.rb b/rswag-specs/spec/rswag/specs/response_validator_spec.rb index 66f2422..1e952e0 100644 --- a/rswag-specs/spec/rswag/specs/response_validator_spec.rb +++ b/rswag-specs/spec/rswag/specs/response_validator_spec.rb @@ -11,7 +11,7 @@ module Rswag allow(config).to receive(:get_swagger_doc).and_return(swagger_doc) end let(:config) { double('config') } - let(:swagger_doc) { {:components => {}} } + let(:swagger_doc) {{}} let(:example) { double('example') } let(:metadata) do { @@ -58,13 +58,7 @@ module Rswag context 'referenced schemas' do before do - # swagger_doc[:definitions] = { - # 'blog' => { - # type: :object, - # properties: { foo: { type: :string } }, - # required: ['foo'] - # } - # } + swagger_doc[:components] = {} swagger_doc[:components][:schemas] = { 'blog' => { type: :object,