forked from loafle/openapi-generator-original
[python] Triple quote strings with new lines in default values (#4941)
* Triple quote python strings in defaults When the model contains a string with a default value with new lines in it, simply quoting generates invalid python code. Using triple quotes for all string defaults makes sure the generated code will be a valid python string. Fixes #4862 * Wrap default string in triple quotes when it contains new lines * Add newly generated python sample files
This commit is contained in:
parent
122194c30e
commit
7de1eeb987
@ -17,6 +17,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@ -519,6 +520,9 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
if (p instanceof StringProperty) {
|
if (p instanceof StringProperty) {
|
||||||
StringProperty dp = (StringProperty) p;
|
StringProperty dp = (StringProperty) p;
|
||||||
if (dp.getDefault() != null) {
|
if (dp.getDefault() != null) {
|
||||||
|
if (Pattern.compile("\r\n|\r|\n").matcher(dp.getDefault()).find())
|
||||||
|
return "'''" + dp.getDefault() + "'''";
|
||||||
|
else
|
||||||
return "'" + dp.getDefault() + "'";
|
return "'" + dp.getDefault() + "'";
|
||||||
}
|
}
|
||||||
} else if (p instanceof BooleanProperty) {
|
} else if (p instanceof BooleanProperty) {
|
||||||
|
@ -116,7 +116,7 @@ class ApiClient(object):
|
|||||||
collection_formats)
|
collection_formats)
|
||||||
for k, v in path_params:
|
for k, v in path_params:
|
||||||
resource_path = resource_path.replace(
|
resource_path = resource_path.replace(
|
||||||
'{%s}' % k, quote(str(v), safe=""))
|
'{%s}' % k, quote(str(v), safe='')) # no safe chars, encode everything
|
||||||
|
|
||||||
# query parameters
|
# query parameters
|
||||||
if query_params:
|
if query_params:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
certifi >= 14.05.14
|
certifi >= 14.05.14
|
||||||
six == 1.8.0
|
six >= 1.10
|
||||||
python_dateutil >= 2.5.3
|
python_dateutil >= 2.5.3
|
||||||
setuptools >= 21.0.0
|
setuptools >= 21.0.0
|
||||||
urllib3 >= 1.15.1
|
urllib3 >= 1.15.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user