File tree Expand file tree Collapse file tree 3 files changed +11
-2
lines changed
modules/openapi-generator/src
main/java/org/openapitools/codegen/languages
test/java/org/openapitools/codegen/python Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -634,7 +634,7 @@ public String toDefaultValue(Schema p) {
634634 if (Pattern .compile ("\r \n |\r |\n " ).matcher ((String ) p .getDefault ()).find ())
635635 return "'''" + p .getDefault () + "'''" ;
636636 else
637- return "'" + p .getDefault () + "'" ;
637+ return "'" + (( String ) p .getDefault ()). replaceAll ( "'" , " \' " ) + "'" ;
638638 }
639639 } else if (ModelUtils .isArraySchema (p )) {
640640 if (p .getDefault () != null ) {
Original file line number Diff line number Diff line change @@ -569,7 +569,7 @@ public String toDefaultValue(Schema p) {
569569 if (Pattern .compile ("\r \n |\r |\n " ).matcher ((String ) p .getDefault ()).find ())
570570 return "'''" + p .getDefault () + "'''" ;
571571 else
572- return "'" + p .getDefault () + "'" ;
572+ return "'" + (( String ) p .getDefault ()). replaceAll ( "'" , " \' " ) + "'" ;
573573 }
574574 } else if (ModelUtils .isArraySchema (p )) {
575575 if (p .getDefault () != null ) {
Original file line number Diff line number Diff line change @@ -92,4 +92,13 @@ public void testRegularExpressionOpenAPISchemaVersion3() {
9292 // pattern_with_modifiers '/^pattern\d{3}$/i
9393 Assert .assertEquals (op .allParams .get (5 ).pattern , "/^pattern\\ d{3}$/i" );
9494 }
95+
96+ @ Test (description = "test single quotes escape" )
97+ public void testSingleQuotes () {
98+ final PythonClientCodegen codegen = new PythonClientCodegen ();
99+ StringSchema schema = new StringSchema ();
100+ schema .setDefault ("Text containing 'single' quote" );
101+ String defaultValue = codegen .toDefaultValue (schema );
102+ Assert .assertEquals ("'Text containing \' single\' quote'" , defaultValue );
103+ }
95104}
You can’t perform that action at this time.
0 commit comments