Skip to content

Commit

Permalink
add option to add ensure_ascii=False in jsom.dumps
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Jun 10, 2024
1 parent d8f5f52 commit 666bbf8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ templateDir: modules/openapi-generator/src/main/resources/python
additionalProperties:
hideGenerationTimestamp: "true"
disallowAdditionalPropertiesIfNotPresent: "true"
setEnsureAsciiToFalse: true
1 change: 1 addition & 0 deletions docs/generators/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|packageVersion|python package version.| |1.0.0|
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
|setEnsureAsciiToFalse|When set to true, add `ensure_ascii=False` in json.dumps when creating the HTTP request body.| |false|
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped.| |false|

## IMPORT MAPPING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ public class PythonClientCodegen extends AbstractPythonCodegen implements Codege
public static final String RECURSION_LIMIT = "recursionLimit";
public static final String DATETIME_FORMAT = "datetimeFormat";
public static final String DATE_FORMAT = "dateFormat";
public static final String SET_ENSURE_ASCII_TO_FALSE = "setEnsureAsciiToFalse";

@Setter protected String packageUrl;
protected String apiDocPath = "docs/";
protected String modelDocPath = "docs/";
@Setter protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
@Setter protected String datetimeFormat = "%Y-%m-%dT%H:%M:%S.%f%z";
@Setter protected String dateFormat = "%Y-%m-%d";

@Setter protected boolean setEnsureAsciiToFalse = false;

private String testFolder;

Expand Down Expand Up @@ -135,6 +136,8 @@ public PythonClientCodegen() {
.defaultValue(Boolean.TRUE.toString()));
cliOptions.add(new CliOption(CodegenConstants.SOURCECODEONLY_GENERATION, CodegenConstants.SOURCECODEONLY_GENERATION_DESC)
.defaultValue(Boolean.FALSE.toString()));
cliOptions.add(new CliOption(SET_ENSURE_ASCII_TO_FALSE, "When set to true, add `ensure_ascii=False` in json.dumps when creating the HTTP request body.")
.defaultValue(Boolean.FALSE.toString()));
cliOptions.add(new CliOption(RECURSION_LIMIT, "Set the recursion limit. If not set, use the system default value."));
cliOptions.add(new CliOption(MAP_NUMBER_TO, "Map number to Union[StrictFloat, StrictInt], StrictStr or float.")
.defaultValue("Union[StrictFloat, StrictInt]"));
Expand Down Expand Up @@ -222,6 +225,10 @@ public void processOpts() {
additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);

if (additionalProperties.containsKey(SET_ENSURE_ASCII_TO_FALSE)) {
additionalProperties.put(SET_ENSURE_ASCII_TO_FALSE, Boolean.valueOf(additionalProperties.get(SET_ENSURE_ASCII_TO_FALSE).toString()));
}

if (additionalProperties.containsKey(PACKAGE_URL)) {
setPackageUrl((String) additionalProperties.get(PACKAGE_URL));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class RESTClientObject:
):
request_body = None
if body is not None:
request_body = json.dumps(body, ensure_ascii={{ensureAscii}})
request_body = json.dumps(body{{#setEnsureAsciiToFalse}}, ensure_ascii=False{{/setEnsureAsciiToFalse}})
r = self.pool_manager.request(
method,
url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def request(
):
request_body = None
if body is not None:
request_body = json.dumps(body)
request_body = json.dumps(body, ensure_ascii=False)
r = self.pool_manager.request(
method,
url,
Expand Down

0 comments on commit 666bbf8

Please sign in to comment.