Ruby: support binary (byte array) for body parameter and response

This commit is contained in:
xhh
2016-01-21 18:01:03 +08:00
parent 5d156916d7
commit aad0547b40
9 changed files with 167 additions and 48 deletions

View File

@@ -86,6 +86,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("map", "Hash");
typeMapping.put("object", "Object");
typeMapping.put("file", "File");
typeMapping.put("binary", "Byte Array");
// remove modelPackage and apiPackage added by default
Iterator<CliOption> itr = cliOptions.iterator();

View File

@@ -70,9 +70,10 @@ module {{moduleName}}
# http body (model)
{{^bodyParam}}post_body = nil
{{/bodyParam}}{{#bodyParam}}post_body = @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}})
{{/bodyParam}}
{{/bodyParam}}{{#bodyParam}}{{#isBinary}}post_body = {{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}
post_body = post_body.pack('C*') if post_body
{{/isBinary}}{{^isBinary}}post_body = @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}})
{{/isBinary}}{{/bodyParam}}
auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]
data, status_code, headers = @api_client.call_api(:{{httpMethod}}, path,
:header_params => header_params,
@@ -90,7 +91,3 @@ module {{moduleName}}
end
{{/operations}}
end

View File

@@ -106,6 +106,9 @@ module {{moduleName}}
body = response.body
return nil if body.nil? || body.empty?
# handle binary response (byte array)
return body.bytes if return_type == 'Byte Array'
# handle file downloading - save response body into a tmp file and return the File instance
return download_file(response) if return_type == 'File'