From da230a4f3ecd57e7ea27c667abf52e9384d533d1 Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Sat, 21 Mar 2020 23:15:56 +0000 Subject: [PATCH] add header type schema support for openapi3 --- .../lib/rswag/specs/example_group_helpers.rb | 6 ------ rswag-specs/lib/rswag/specs/swagger_formatter.rb | 3 ++- .../spec/rswag/specs/example_helpers_spec.rb | 14 -------------- .../spec/rswag/specs/swagger_formatter_spec.rb | 12 +++++++++--- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/rswag-specs/lib/rswag/specs/example_group_helpers.rb b/rswag-specs/lib/rswag/specs/example_group_helpers.rb index 812e283..227b4ed 100644 --- a/rswag-specs/lib/rswag/specs/example_group_helpers.rb +++ b/rswag-specs/lib/rswag/specs/example_group_helpers.rb @@ -157,12 +157,6 @@ module Rswag def header(name, attributes) metadata[:response][:headers] ||= {} - ## OA3 - # if attributes[:type] && attributes[:schema].nil? - # attributes[:schema] = { type: attributes[:type] } - # attributes.delete(:type) - # end - metadata[:response][:headers][name] = attributes end diff --git a/rswag-specs/lib/rswag/specs/swagger_formatter.rb b/rswag-specs/lib/rswag/specs/swagger_formatter.rb index 1c8fba3..6aeeb55 100644 --- a/rswag-specs/lib/rswag/specs/swagger_formatter.rb +++ b/rswag-specs/lib/rswag/specs/swagger_formatter.rb @@ -127,8 +127,9 @@ module Rswag def upgrade_request_type!(metadata) operation_nodes = metadata[:operation][:parameters] || [] path_nodes = metadata[:path_item][:parameters] || [] + header_node = metadata[:response][:headers] ||= {} - (operation_nodes + path_nodes).each do |node| + (operation_nodes + path_nodes + [header_node]).each do |node| if node && node[:type] && node[:schema].nil? node[:schema] = { type: node[:type] } node.delete(:type) diff --git a/rswag-specs/spec/rswag/specs/example_helpers_spec.rb b/rswag-specs/spec/rswag/specs/example_helpers_spec.rb index 51cac79..b4e7be8 100644 --- a/rswag-specs/spec/rswag/specs/example_helpers_spec.rb +++ b/rswag-specs/spec/rswag/specs/example_helpers_spec.rb @@ -27,20 +27,6 @@ module Rswag } } end - ## OA3 - # let(:swagger_doc) do - # { - # components: { - # securitySchemes: { - # api_key: { - # type: :apiKey, - # name: 'api_key', - # in: :query - # } - # } - # } - # } - # end let(:metadata) do { diff --git a/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb b/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb index 4ab7777..33b9344 100644 --- a/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb +++ b/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb @@ -28,7 +28,7 @@ module Rswag { path_item: { template: '/blogs', parameters: [{ type: :string }] }, operation: { verb: :post, summary: 'Creates a blog', parameters: [{ type: :string }] }, - response: { code: '201', description: 'blog created' }, + response: { code: '201', description: 'blog created', headers: { type: :string } }, document: document } end @@ -55,7 +55,10 @@ module Rswag parameters: [{ type: :string }], summary: 'Creates a blog', responses: { - '201' => { description: 'blog created' } + '201' => { + description: 'blog created', + headers: { type: :string } + } } } } @@ -78,7 +81,10 @@ module Rswag parameters: [{ schema: { type: :string } }], summary: 'Creates a blog', responses: { - '201' => { description: 'blog created' } + '201' => { + description: 'blog created', + headers: { schema: { type: :string } } + } } } }