fix do not delete from operation level metadata

This commit is contained in:
Greg Myers 2020-03-29 20:16:03 +01:00
parent 405ccca494
commit 1f745003ff
2 changed files with 49 additions and 18 deletions

View File

@ -34,6 +34,9 @@ module Rswag
swagger_doc = @config.get_swagger_doc(metadata[:swagger_doc]) swagger_doc = @config.get_swagger_doc(metadata[:swagger_doc])
unless doc_version(swagger_doc).start_with?('2') unless doc_version(swagger_doc).start_with?('2')
# This is called once PER EXAMPLE ('it' block) not on group finished.
# metadata[:operation] is also re-used between examples so be careful
# NOT to modify its content here.
upgrade_request_type!(metadata) upgrade_request_type!(metadata)
upgrade_servers!(swagger_doc) upgrade_servers!(swagger_doc)
upgrade_oauth!(swagger_doc) upgrade_oauth!(swagger_doc)
@ -83,14 +86,14 @@ module Rswag
def upgrade_request_consumes!(swagger_doc, metadata) def upgrade_request_consumes!(swagger_doc, metadata)
# Content-Type header # Content-Type header
mime_list = Array(metadata[:operation].delete(:consumes) || swagger_doc[:consumes]) mime_list = Array(metadata[:operation][:consumes] || swagger_doc[:consumes])
target_node = metadata[:response] target_node = metadata[:response]
upgrade_content!(mime_list, target_node) upgrade_content!(mime_list, target_node)
end end
def upgrade_response_produces!(swagger_doc, metadata) def upgrade_response_produces!(swagger_doc, metadata)
# Accept header # Accept header
mime_list = Array(metadata[:operation].delete(:produces) || swagger_doc[:produces]) mime_list = Array(metadata[:operation][:produces] || swagger_doc[:produces])
target_node = metadata[:response] target_node = metadata[:response]
upgrade_content!(mime_list, target_node) upgrade_content!(mime_list, target_node)
metadata[:response].delete(:schema) metadata[:response].delete(:schema)
@ -99,7 +102,7 @@ module Rswag
def upgrade_content!(mime_list, target_node) def upgrade_content!(mime_list, target_node)
target_node.merge!(content: {}) target_node.merge!(content: {})
schema = target_node[:schema] schema = target_node[:schema]
return if mime_list.empty? return if mime_list.empty? || schema.nil?
mime_list.each do |mime_type| mime_list.each do |mime_type|
# TODO upgrade to have content-type specific schema # TODO upgrade to have content-type specific schema

View File

@ -21,10 +21,14 @@
], ],
"responses": { "responses": {
"204": { "204": {
"description": "Valid credentials" "description": "Valid credentials",
"content": {
}
}, },
"401": { "401": {
"description": "Invalid credentials" "description": "Invalid credentials",
"content": {
}
} }
} }
} }
@ -45,10 +49,14 @@
], ],
"responses": { "responses": {
"204": { "204": {
"description": "Valid credentials" "description": "Valid credentials",
"content": {
}
}, },
"401": { "401": {
"description": "Invalid credentials" "description": "Invalid credentials",
"content": {
}
} }
} }
} }
@ -72,10 +80,14 @@
], ],
"responses": { "responses": {
"204": { "204": {
"description": "Valid credentials" "description": "Valid credentials",
"content": {
}
}, },
"401": { "401": {
"description": "Invalid credentials" "description": "Invalid credentials",
"content": {
}
} }
} }
} }
@ -105,12 +117,18 @@
], ],
"responses": { "responses": {
"201": { "201": {
"description": "blog created" "description": "blog created",
"content": {
}
}, },
"422": { "422": {
"description": "invalid request", "description": "invalid request",
"schema": { "content": {
"$ref": "#/definitions/errors_object" "application/json": {
"schema": {
"$ref": "#/definitions/errors_object"
}
}
} }
} }
} }
@ -136,7 +154,9 @@
], ],
"responses": { "responses": {
"406": { "406": {
"description": "unsupported accept header" "description": "unsupported accept header",
"content": {
}
} }
} }
} }
@ -176,9 +196,6 @@
"type": "string" "type": "string"
} }
}, },
"schema": {
"$ref": "#/definitions/blog"
},
"examples": { "examples": {
"application/json": { "application/json": {
"id": 1, "id": 1,
@ -186,10 +203,19 @@
"content": "Hello world and hello universe. Thank you all very much!!!", "content": "Hello world and hello universe. Thank you all very much!!!",
"thumbnail": "thumbnail.png" "thumbnail": "thumbnail.png"
} }
},
"content": {
"application/json": {
"schema": {
"$ref": "#/definitions/blog"
}
}
} }
}, },
"404": { "404": {
"description": "blog not found" "description": "blog not found",
"content": {
}
} }
} }
} }
@ -227,7 +253,9 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": "blog updated" "description": "blog updated",
"content": {
}
} }
} }
} }