fix mistake in assigning header nodes for type

This commit is contained in:
Greg Myers 2020-03-22 23:45:47 +00:00
parent eb58fe687a
commit e9aebe6221
3 changed files with 20 additions and 38 deletions

View File

@ -128,7 +128,7 @@ module Rswag
def upgrade_request_type!(metadata) def upgrade_request_type!(metadata)
operation_nodes = metadata[:operation][:parameters] || [] operation_nodes = metadata[:operation][:parameters] || []
path_nodes = metadata[:path_item][: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| (operation_nodes + path_nodes + [header_node]).each do |node|
if node && node[:type] && node[:schema].nil? if node && node[:type] && node[:schema].nil?

View File

@ -78,11 +78,7 @@ module Rswag
let(:document) { nil } let(:document) { nil }
it 'converts query and path params, type: to schema: { type: }' do it 'converts query and path params, type: to schema: { type: }' do
expect(swagger_doc).to match( expect(swagger_doc.slice(:paths)).to match(
openapi: '3.0.1',
servers: {
urls: ['http://api.example.com/foo', 'https://api.example.com/foo']
},
paths: { paths: {
'/blogs' => { '/blogs' => {
parameters: [{ schema: { type: :string } }], parameters: [{ schema: { type: :string } }],
@ -100,6 +96,14 @@ module Rswag
} }
) )
end 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
end end

View File

@ -21,14 +21,10 @@
], ],
"responses": { "responses": {
"204": { "204": {
"description": "Valid credentials", "description": "Valid credentials"
"headers": {
}
}, },
"401": { "401": {
"description": "Invalid credentials", "description": "Invalid credentials"
"headers": {
}
} }
} }
} }
@ -49,14 +45,10 @@
], ],
"responses": { "responses": {
"204": { "204": {
"description": "Valid credentials", "description": "Valid credentials"
"headers": {
}
}, },
"401": { "401": {
"description": "Invalid credentials", "description": "Invalid credentials"
"headers": {
}
} }
} }
} }
@ -80,14 +72,10 @@
], ],
"responses": { "responses": {
"204": { "204": {
"description": "Valid credentials", "description": "Valid credentials"
"headers": {
}
}, },
"401": { "401": {
"description": "Invalid credentials", "description": "Invalid credentials"
"headers": {
}
} }
} }
} }
@ -117,16 +105,12 @@
], ],
"responses": { "responses": {
"201": { "201": {
"description": "blog created", "description": "blog created"
"headers": {
}
}, },
"422": { "422": {
"description": "invalid request", "description": "invalid request",
"schema": { "schema": {
"$ref": "#/definitions/errors_object" "$ref": "#/definitions/errors_object"
},
"headers": {
} }
} }
} }
@ -152,9 +136,7 @@
], ],
"responses": { "responses": {
"406": { "406": {
"description": "unsupported accept header", "description": "unsupported accept header"
"headers": {
}
} }
} }
} }
@ -207,9 +189,7 @@
} }
}, },
"404": { "404": {
"description": "blog not found", "description": "blog not found"
"headers": {
}
} }
} }
} }
@ -247,9 +227,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": "blog updated", "description": "blog updated"
"headers": {
}
} }
} }
} }