Skip to content

Commit f2191a2

Browse files
committed
Fix single quote escaping for python code generator (and its test)
Hard to spot, but in Java the strings "'" and "\'" are identical, so the implementation and its test were broken identically.
1 parent 04169ec commit f2191a2

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public String toDefaultValue(Schema p) {
214214
String defaultValue = String.valueOf(p.getDefault());
215215
if (defaultValue != null) {
216216
defaultValue = defaultValue.replace("\\", "\\\\")
217-
.replace("'", "\'");
217+
.replace("'", "\\'");
218218
if (Pattern.compile("\r\n|\r|\n").matcher(defaultValue).find()) {
219219
return "'''" + defaultValue + "'''";
220220
} else {

modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientCodegenTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void testSingleQuotes() {
139139
StringSchema schema = new StringSchema();
140140
schema.setDefault("Text containing 'single' quote");
141141
String defaultValue = codegen.toDefaultValue(schema);
142-
Assert.assertEquals("'Text containing \'single\' quote'", defaultValue);
142+
Assert.assertEquals("'Text containing \\'single\\' quote'", defaultValue);
143143
}
144144

145145
@Test(description = "test backslash default")

0 commit comments

Comments
 (0)