@@ -454,29 +454,6 @@ public String escapeQuotationMark(String input) {
454454 return input .replace ("\" " , "\\ \" " );
455455 }
456456
457- protected String escapeRegex (String pattern ) {
458- pattern = pattern .replaceAll ("\\ \\ \\ \\ " , "\\ \\ " );
459- pattern = pattern .replaceAll ("^/" , "" );
460- pattern = pattern .replaceAll ("/$" , "" );
461- return pattern ;
462- }
463-
464- /**
465- * Convert OpenAPI Parameter object to Codegen Parameter object
466- *
467- * @param imports set of imports for library/package/module
468- * @param param OpenAPI parameter object
469- * @return Codegen Parameter object
470- */
471- @ Override
472- public CodegenParameter fromParameter (Parameter param , Set <String > imports ) {
473- CodegenParameter parameter = super .fromParameter (param , imports );
474- if (parameter .pattern != null ) {
475- parameter .pattern = escapeRegex (parameter .pattern );
476- }
477- return parameter ;
478- }
479-
480457 /**
481458 * Convert OAS Property schema to Codegen Property object.
482459 * <p>
@@ -498,9 +475,6 @@ public CodegenProperty fromProperty(String name, Schema schema, boolean required
498475 if (needsVarEscape (property .name )) {
499476 property .name = "var\" " + property .name + "\" " ;
500477 }
501- if (property .pattern != null ) {
502- property .pattern = escapeRegex (property .pattern );
503- }
504478 return property ;
505479 }
506480
@@ -531,15 +505,17 @@ private void changeParamNames(List<CodegenParameter> paramsList, HashSet<String>
531505 }
532506 }
533507
534- // The DefaultCodegen.toRegularExpression method returns regex in a format
535- // that is unsuitable for use in Julia. This method changes the regex to
536- // a suitable format.
537- private void changeRegexEscape (List <CodegenParameter > paramsList ) {
538- for (CodegenParameter param : paramsList ) {
539- if (param .pattern != null ) {
540- param .pattern = escapeRegex (param .pattern );
541- }
508+ @ Override
509+ public String toRegularExpression (String pattern ) {
510+ if (pattern == null ) {
511+ return pattern ;
542512 }
513+
514+ pattern = escapeText (pattern );
515+ // escapeText unnecessarily escapes `\` such that `\.` in the regex ends up as `\\.` for example.
516+ // we need to restore it back by converting `\\` to `\`
517+ pattern = pattern .replaceAll ("\\ \\ \\ \\ " , "\\ \\ " );
518+ return pattern ;
543519 }
544520
545521 /**
@@ -573,13 +549,6 @@ public CodegenOperation fromOperation(String path,
573549 changeParamNames (op .queryParams , reservedNames );
574550 changeParamNames (op .formParams , reservedNames );
575551
576- changeRegexEscape (op .allParams );
577- changeRegexEscape (op .bodyParams );
578- changeRegexEscape (op .headerParams );
579- changeRegexEscape (op .pathParams );
580- changeRegexEscape (op .queryParams );
581- changeRegexEscape (op .formParams );
582-
583552 return op ;
584553 }
585554
0 commit comments