OpenAPITools / OpenAPITools/openapi-generator

openapi-generator-maven-plugin generate ascii with Description without escaping unsafe characters

Open
#11,468 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Hi,
i am using the openapi-generator-maven-plugin to generate Ascii from a json file.
My Json File has some special Formatations like \n for new lines in the descirption, but the Plugin deletes the Formatation.

I found a Function in the openapi-generator and i think thats the reason why my Formatation is deleted.

  // remove \t, \n, \r
     // replace \ with \\
     // replace " with \"
     // outer unescape to retain the original multi-byte characters
     // finally escalate characters avoiding code injection
     return escapeUnsafeCharacters(
             StringEscapeUtils.unescapeJava(
                     StringEscapeUtils.escapeJava(input)
                             .replace("\\/", "/"))
                     .replaceAll("[\\t\\n\\r]", " ")
                     .replace("\\", "\\\\")
                     .replace("\"", "\\\""));

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

I am using the Plugin like this:

               <plugin>
                  <groupId>org.openapitools</groupId>
                  <artifactId>openapi-generator-maven-plugin</artifactId>
                  <version>5.3.1</version>
                  <executions>
                     <execution>
                        <goals>
                           <goal>generate</goal>
                        </goals>
                        <configuration>
                           <inputSpec>openapi.json</inputSpec>
                           <generatorName>asciidoc</generatorName>
                           <skipValidateSpec>true</skipValidateSpec>
                           <configOptions>
                              <useIntroduction>true</useIntroduction>
                              <useMethodAndPath>true</useMethodAndPath>
                              <useTableTitles>true</useTableTitles>
                           </configOptions>
                           <output>output</output>
                        </configuration>
                     </execution>
                  </executions>
               </plugin>

Is there a way to use the plugin with my Formatation?

Describe the solution you'd like

A Possibility to insert Formatations to the Descriptions

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java, focusing on the escaping function shown in the issue. Reproduce the behavior with the openapi-generator-maven-plugin 5.3.1 and an OpenAPI JSON description containing formatting characters, then verify that generated AsciiDoc preserves the requested formatting without unsafe-character injection.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.