[python] Add an option to add ensure_ascii=False to json.dumps (#18888)

* Added ensure ascii

* add option to add ensure_ascii=False in jsom.dumps

* remove option

* update workflow

---------

Co-authored-by: Emile Girard <Emile.Girard@opal-rt.com>
This commit is contained in:
William Cheng 2024-06-15 18:39:06 +08:00 committed by GitHub
parent a40673acb9
commit 13facdaab5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 13 additions and 3 deletions

View File

@ -4,6 +4,7 @@ on:
pull_request:
paths:
- samples/client/echo_api/python/**
- samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/**
- .github/workflows/samples-python-client-echo-api.yaml
jobs:
build:

View File

@ -5,3 +5,4 @@ templateDir: modules/openapi-generator/src/main/resources/python
additionalProperties:
hideGenerationTimestamp: "true"
disallowAdditionalPropertiesIfNotPresent: "true"
setEnsureAsciiToFalse: true

View File

@ -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

View File

@ -43,6 +43,7 @@ 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/";
@ -50,7 +51,7 @@ public class PythonClientCodegen extends AbstractPythonCodegen implements Codege
@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;
@ -135,6 +136,8 @@ public class PythonClientCodegen extends AbstractPythonCodegen implements Codege
.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]"));
@ -222,6 +225,10 @@ public class PythonClientCodegen extends AbstractPythonCodegen implements Codege
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));
}

View File

@ -168,7 +168,7 @@ class RESTClientObject:
):
request_body = None
if body is not None:
request_body = json.dumps(body)
request_body = json.dumps(body{{#setEnsureAsciiToFalse}}, ensure_ascii=False{{/setEnsureAsciiToFalse}})
r = self.pool_manager.request(
method,
url,

View File

@ -179,7 +179,7 @@ class RESTClientObject:
):
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,