add upgrade path and query param type output to openapi3 if selected

This commit is contained in:
Greg Myers
2020-03-21 21:27:22 +00:00
parent 23a1074d07
commit 70eb277e04
4 changed files with 67 additions and 18 deletions

View File

@@ -131,11 +131,6 @@ module Rswag
attributes[:required] = true
end
## IF OA3
# if attributes[:type] && attributes[:schema].nil?
# attributes[:schema] = {type: attributes[:type]}
# end
if metadata.has_key?(:operation)
metadata[:operation][:parameters] ||= []
metadata[:operation][:parameters] << attributes
@@ -164,7 +159,7 @@ module Rswag
## OA3
# if attributes[:type] && attributes[:schema].nil?
# attributes[:schema] = {type: attributes[:type]}
# attributes[:schema] = { type: attributes[:type] }
# attributes.delete(:type)
# end

View File

@@ -33,12 +33,16 @@ module Rswag
return unless metadata.has_key?(:response)
swagger_doc = @config.get_swagger_doc(metadata[:swagger_doc])
if doc_version(swagger_doc).starts_with?('3')
upgrade_request_type!(metadata)
end
swagger_doc.deep_merge!(metadata_to_swagger(metadata))
end
def stop(_notification=nil)
@config.swagger_docs.each do |url_path, doc|
## OA3
# # remove 2.0 parameters
# doc[:paths]&.each_pair do |_k, v|
@@ -115,6 +119,22 @@ module Rswag
{ paths: { path_template => path_item } }
end
def doc_version(doc)
doc[:openapi] || doc[:swagger] || '3'
end
def upgrade_request_type!(metadata)
operation_nodes = metadata[:operation][:parameters] || []
path_nodes = metadata[:path_item][:parameters] || []
(operation_nodes + path_nodes).each do |node|
if node && node[:type] && node[:schema].nil?
node[:schema] = { type: node[:type] }
node.delete(:type)
end
end
end
end
end
end