update all petstore security samples

This commit is contained in:
wing328
2017-10-18 10:10:44 +08:00
parent c4d5ba1533
commit c783ec1d41
60 changed files with 445 additions and 290 deletions

View File

@@ -6,6 +6,7 @@
OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r
Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.3.0-SNAPSHOT
=end

View File

@@ -6,6 +6,7 @@
OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r
Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.3.0-SNAPSHOT
=end
@@ -122,7 +123,9 @@ module Petstore
end
end
Typhoeus::Request.new(url, req_opts)
request = Typhoeus::Request.new(url, req_opts)
download_file(request) if opts[:return_type] == 'File'
request
end
# Check if the given MIME is a JSON MIME.
@@ -143,14 +146,16 @@ module Petstore
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
def deserialize(response, return_type)
body = response.body
# handle file downloading - return the File instance processed in request callbacks
# note that response body is empty when the file is written in chunks in request on_body callback
return @tempfile if return_type == 'File'
return nil if body.nil? || body.empty?
# return response body directly for String return type
return body if return_type == 'String'
# handle file downloading - save response body into a tmp file and return the File instance
return download_file(response) if return_type == 'File'
# ensuring a default content type
content_type = response.headers['Content-Type'] || 'application/json'
@@ -213,30 +218,38 @@ module Petstore
# Save response body into a file in (the defined) temporary folder, using the filename
# from the "Content-Disposition" header if provided, otherwise a random filename.
# The response body is written to the file in chunks in order to handle files which
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
# process can use.
#
# @see Configuration#temp_folder_path
# @return [Tempfile] the file downloaded
def download_file(response)
content_disposition = response.headers['Content-Disposition']
if content_disposition and content_disposition =~ /filename=/i
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
prefix = sanitize_filename(filename)
else
prefix = 'download-'
end
prefix = prefix + '-' unless prefix.end_with?('-')
def download_file(request)
tempfile = nil
encoding = response.body.encoding
Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
file.write(response.body)
tempfile = file
encoding = nil
request.on_headers do |response|
content_disposition = response.headers['Content-Disposition']
if content_disposition and content_disposition =~ /filename=/i
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
prefix = sanitize_filename(filename)
else
prefix = 'download-'
end
prefix = prefix + '-' unless prefix.end_with?('-')
encoding = response.body.encoding
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
@tempfile = tempfile
end
request.on_body do |chunk|
chunk.force_encoding(encoding)
tempfile.write(chunk)
end
request.on_complete do |response|
tempfile.close
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
"explicitly with `tempfile.delete`"
end
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
"explicitly with `tempfile.delete`"
tempfile
end
# Sanitize filename by removing path.
@@ -267,7 +280,7 @@ module Petstore
data = {}
form_params.each do |key, value|
case value
when File, Array, nil
when ::File, ::Array, nil
# let typhoeus handle File, Array and nil parameters
data[key] = value
else

View File

@@ -6,6 +6,7 @@
OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r
Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.3.0-SNAPSHOT
=end

View File

@@ -6,6 +6,7 @@
OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r
Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.3.0-SNAPSHOT
=end
@@ -75,6 +76,11 @@ module Petstore
# Default to 0 (never times out).
attr_accessor :timeout
# Set this to false to skip client side validation in the operation.
# Default to true.
# @return [true, false]
attr_accessor :client_side_validation
### TLS/SSL setting
# Set this to false to skip verifying SSL certificate when calling API from https server.
# Default to true.
@@ -128,6 +134,7 @@ module Petstore
@api_key = {}
@api_key_prefix = {}
@timeout = 0
@client_side_validation = true
@verify_ssl = true
@verify_ssl_host = true
@params_encoding = nil

View File

@@ -6,6 +6,7 @@
OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r
Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.3.0-SNAPSHOT
=end

View File

@@ -6,6 +6,7 @@
OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r
Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.3.0-SNAPSHOT
=end