|
16 | 16 |
|
17 | 17 | package org.openapitools.codegen.languages;
|
18 | 18 |
|
| 19 | +import com.samskivert.mustache.Escapers; |
| 20 | +import com.samskivert.mustache.Mustache; |
19 | 21 | import io.swagger.v3.oas.models.media.Schema;
|
20 | 22 | import org.openapitools.codegen.*;
|
21 | 23 | import org.openapitools.codegen.meta.features.*;
|
@@ -557,7 +559,34 @@ public String getHelp() {
|
557 | 559 |
|
558 | 560 | @Override
|
559 | 561 | public String escapeReservedWord(String name) {
|
560 |
| - return "_" + name; |
| 562 | + if (this.reservedWordsMappings().containsKey(name)) { |
| 563 | + return this.reservedWordsMappings().get(name); |
| 564 | + } |
| 565 | + // Reserved words will be further escaped at the mustache compiler level. |
| 566 | + // Scala escaping done here (via `, without compiler escaping) would otherwise be HTML encoded. |
| 567 | + return "`" + name + "`"; |
| 568 | + } |
| 569 | + |
| 570 | + @Override |
| 571 | + public Mustache.Compiler processCompiler(Mustache.Compiler compiler) { |
| 572 | + Mustache.Escaper SCALA = new Mustache.Escaper() { |
| 573 | + @Override |
| 574 | + public String escape(String text) { |
| 575 | + // Fix included as suggested by akkie in #6393 |
| 576 | + // The given text is a reserved word which is escaped by enclosing it with grave accents. If we would |
| 577 | + // escape that with the default Mustache `HTML` escaper, then the escaper would also escape our grave |
| 578 | + // accents. So we remove the grave accents before the escaping and add it back after the escaping. |
| 579 | + if (text.startsWith("`") && text.endsWith("`")) { |
| 580 | + String unescaped = text.substring(1, text.length() - 1); |
| 581 | + return "`" + Escapers.HTML.escape(unescaped) + "`"; |
| 582 | + } |
| 583 | + |
| 584 | + // All none reserved words will be escaped with the default Mustache `HTML` escaper |
| 585 | + return Escapers.HTML.escape(text); |
| 586 | + } |
| 587 | + }; |
| 588 | + |
| 589 | + return compiler.withEscaper(SCALA); |
561 | 590 | }
|
562 | 591 |
|
563 | 592 | @Override
|
|
0 commit comments