forked from loafle/openapi-generator-original
committed by
William Cheng
parent
632364e290
commit
6283625478
@@ -634,7 +634,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
|
||||
return "'''" + p.getDefault() + "'''";
|
||||
else
|
||||
return "'" + p.getDefault() + "'";
|
||||
return "'" + ((String) p.getDefault()).replaceAll("'","\'") + "'";
|
||||
}
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
|
||||
@@ -569,7 +569,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
|
||||
return "'''" + p.getDefault() + "'''";
|
||||
else
|
||||
return "'" + p.getDefault() + "'";
|
||||
return "'" + ((String) p.getDefault()).replaceAll("'","\'") + "'";
|
||||
}
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
|
||||
@@ -92,4 +92,13 @@ public class PythonClientCodegenTest {
|
||||
// pattern_with_modifiers '/^pattern\d{3}$/i
|
||||
Assert.assertEquals(op.allParams.get(5).pattern, "/^pattern\\d{3}$/i");
|
||||
}
|
||||
|
||||
@Test(description = "test single quotes escape")
|
||||
public void testSingleQuotes() {
|
||||
final PythonClientCodegen codegen = new PythonClientCodegen();
|
||||
StringSchema schema = new StringSchema();
|
||||
schema.setDefault("Text containing 'single' quote");
|
||||
String defaultValue = codegen.toDefaultValue(schema);
|
||||
Assert.assertEquals("'Text containing \'single\' quote'", defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user