@@ -761,6 +761,8 @@ public String toOperationId(String operationId) {
761761 public String toVarName (String name ) {
762762 if (reservedWords .contains (name )) {
763763 return escapeReservedWord (name );
764+ } else if (((CharSequence ) name ).chars ().anyMatch (character -> specialCharReplacements .keySet ().contains ( "" + ((char ) character )))) {
765+ return escapeSpecialCharacters (name , null , null );
764766 } else {
765767 return name ;
766768 }
@@ -777,6 +779,8 @@ public String toParamName(String name) {
777779 name = removeNonNameElementToCamelCase (name ); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
778780 if (reservedWords .contains (name )) {
779781 return escapeReservedWord (name );
782+ } else if (((CharSequence ) name ).chars ().anyMatch (character -> specialCharReplacements .keySet ().contains ( "" + ((char ) character )))) {
783+ return escapeSpecialCharacters (name , null , null );
780784 }
781785 return name ;
782786 }
@@ -815,6 +819,32 @@ public String escapeReservedWord(String name) {
815819 throw new RuntimeException ("reserved word " + name + " not allowed" );
816820 }
817821
822+ /**
823+ * Return the name with escaped characters.
824+ *
825+ * @param name the name to be escaped
826+ * @param charactersToAllow characters that are not escaped
827+ * @param appdendixToReplacement String to append to replaced characters.
828+ * @return the escaped word
829+ * <p>
830+ * throws Runtime exception as word is not escaped properly.
831+ */
832+ public String escapeSpecialCharacters (String name , List <String > charactersToAllow , String appdendixToReplacement ) {
833+ String result = (String ) ((CharSequence ) name ).chars ().mapToObj (c -> {
834+ String character = "" + (char ) c ;
835+ if (charactersToAllow != null && charactersToAllow .contains (character )) {
836+ return character ;
837+ } else if (specialCharReplacements .containsKey (character )) {
838+ return specialCharReplacements .get (character ) + (appdendixToReplacement != null ? appdendixToReplacement : "" );
839+ } else {
840+ return character ;
841+ }
842+ }).reduce ( (c1 , c2 ) -> "" + c1 + c2 ).orElse (null );
843+
844+ if (result != null ) return result ;
845+ throw new RuntimeException ("Word '" + name + "' could not be escaped." );
846+ }
847+
818848 /**
819849 * Return the fully-qualified "Model" name for import
820850 *
0 commit comments