From e9aebe6221cbf44c33cb322dc79f48adfeef2816 Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Sun, 22 Mar 2020 23:45:47 +0000 Subject: [PATCH] fix mistake in assigning header nodes for type --- .../lib/rswag/specs/swagger_formatter.rb | 2 +- .../rswag/specs/swagger_formatter_spec.rb | 14 ++++--- test-app/swagger/v1/swagger.json | 42 +++++-------------- 3 files changed, 20 insertions(+), 38 deletions(-) diff --git a/rswag-specs/lib/rswag/specs/swagger_formatter.rb b/rswag-specs/lib/rswag/specs/swagger_formatter.rb index ea072fe..008a600 100644 --- a/rswag-specs/lib/rswag/specs/swagger_formatter.rb +++ b/rswag-specs/lib/rswag/specs/swagger_formatter.rb @@ -128,7 +128,7 @@ module Rswag def upgrade_request_type!(metadata) operation_nodes = metadata[:operation][:parameters] || [] path_nodes = metadata[:path_item][:parameters] || [] - header_node = metadata[:response][:headers] ||= {} + header_node = metadata[:response][:headers] || {} (operation_nodes + path_nodes + [header_node]).each do |node| if node && node[:type] && node[:schema].nil? diff --git a/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb b/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb index 678462f..319d5dd 100644 --- a/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb +++ b/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb @@ -78,11 +78,7 @@ module Rswag let(:document) { nil } it 'converts query and path params, type: to schema: { type: }' do - expect(swagger_doc).to match( - openapi: '3.0.1', - servers: { - urls: ['http://api.example.com/foo', 'https://api.example.com/foo'] - }, + expect(swagger_doc.slice(:paths)).to match( paths: { '/blogs' => { parameters: [{ schema: { type: :string } }], @@ -100,6 +96,14 @@ module Rswag } ) end + + it 'converts basePath, schemas and host to urls' do + expect(swagger_doc.slice(:servers)).to match( + servers: { + urls: ['http://api.example.com/foo', 'https://api.example.com/foo'] + } + ) + end end end diff --git a/test-app/swagger/v1/swagger.json b/test-app/swagger/v1/swagger.json index e478605..fd380a8 100644 --- a/test-app/swagger/v1/swagger.json +++ b/test-app/swagger/v1/swagger.json @@ -21,14 +21,10 @@ ], "responses": { "204": { - "description": "Valid credentials", - "headers": { - } + "description": "Valid credentials" }, "401": { - "description": "Invalid credentials", - "headers": { - } + "description": "Invalid credentials" } } } @@ -49,14 +45,10 @@ ], "responses": { "204": { - "description": "Valid credentials", - "headers": { - } + "description": "Valid credentials" }, "401": { - "description": "Invalid credentials", - "headers": { - } + "description": "Invalid credentials" } } } @@ -80,14 +72,10 @@ ], "responses": { "204": { - "description": "Valid credentials", - "headers": { - } + "description": "Valid credentials" }, "401": { - "description": "Invalid credentials", - "headers": { - } + "description": "Invalid credentials" } } } @@ -117,16 +105,12 @@ ], "responses": { "201": { - "description": "blog created", - "headers": { - } + "description": "blog created" }, "422": { "description": "invalid request", "schema": { "$ref": "#/definitions/errors_object" - }, - "headers": { } } } @@ -152,9 +136,7 @@ ], "responses": { "406": { - "description": "unsupported accept header", - "headers": { - } + "description": "unsupported accept header" } } } @@ -207,9 +189,7 @@ } }, "404": { - "description": "blog not found", - "headers": { - } + "description": "blog not found" } } } @@ -247,9 +227,7 @@ ], "responses": { "200": { - "description": "blog updated", - "headers": { - } + "description": "blog updated" } } }