Skip to content

Commit 3a9fd55

Browse files
committed
added option for write binary file modes
1 parent 4c0234e commit 3a9fd55

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
2525
public static final String PACKAGE_URL = "packageUrl";
2626
public static final String DEFAULT_LIBRARY = "urllib3";
2727

28+
public static final String WRITE_BINARY_OPTION = "writeBinary";
29+
2830
protected String packageName; // e.g. petstore_api
2931
protected String packageVersion;
3032
protected String projectName; // for setup.py, e.g. petstore-api
@@ -174,6 +176,11 @@ public void processOpts() {
174176
setPackageVersion("1.0.0");
175177
}
176178

179+
if (additionalProperties.containsKey(WRITE_BINARY_OPTION)) {
180+
boolean optionValue = Boolean.parseBoolean(String.valueOf(additionalProperties.get(WRITE_BINARY_OPTION)));
181+
additionalProperties.put(WRITE_BINARY_OPTION, optionValue);
182+
}
183+
177184
additionalProperties.put(CodegenConstants.PROJECT_NAME, projectName);
178185
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
179186
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);

modules/swagger-codegen/src/main/resources/python/api_client.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ class ApiClient(object):
540540
content_disposition).group(1)
541541
path = os.path.join(os.path.dirname(path), filename)
542542

543-
with open(path, "w") as f:
543+
with open(path, {{^writeBinary}}"w"{{/writeBinary}}{{#writeBinary}}"wb"{{/writeBinary}}) as f:
544544
f.write(response.data)
545545

546546
return path

0 commit comments

Comments
 (0)