OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.49k stars 6.5k forks source link

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

Open T-Developer1 opened 2 years ago

T-Developer1 commented 2 years ago

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

T-Developer1 commented 2 years ago

My OpenAPI Json Looks like this:

{
    "openapi": "3.0.1",
    "info": {
        "title": "TestOpenAPI",
        "description": "Testdescription",
        "version": "1.2.3"
    },
    "servers": [
        {
            "url": "http://TestServer"
        }
    ],
    "tags": [
        {
            "name": "testTag",
            "description": "TestDescription"
        }
    ],
    "paths": {
        "/texts": {
            "get": {
                "tags": [
                    "TestTag1"
                ],
                "operationId": "testOperation",
                "parameters": [
                    {
                        "name": "testName",
                        "in": "query",
                        "description": "TestDescription \n Line2 TestDescription",
                        "required": true,
                        "schema": {
                            "pattern": "^(([a-z]{2}_[A-Z]{2})+,){0,9}([a-z]{2}_[A-Z]{2}){1}$",
                            "type": "string",
                            "description": "TestDescription \n Line2 TestDescription"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "*/*": {
                                "schema": {
                                    "oneOf": [
                                        {
                                            "$ref": "#/components/schemas/test"
                                        },
                                        {
                                            "$ref": "#/components/schemas/test2"
                                        }
                                    ]
                                }
                            }
                        }
                    }
                }
            }
        },
        "components": {
            "schemas": {
                "test": {
                    "type": "object",
                    "properties": {
                        "texts": {
                            "type": "array",
                            "xml": {
                                "name": "text"
                            },
                            "items": {
                                "$ref": "#/components/schemas/test"
                            }
                        }
                    },
                    "xml": {
                        "name": "texts"
                    }
                },
                "TextType": {
                    "required": [],
                    "type": "object",
                    "properties": {
                        "key": {
                            "type": "string",
                            "description": "The key of the text"
                        },
                        "value": {
                            "type": "string",
                            "description": "The value of the text"
                        },
                        "category": {
                            "type": "string",
                            "description": "The category of the text"
                        },
                        "language": {
                            "maxLength": 5,
                            "minLength": 5,
                            "pattern": "[a-z]{2}_[A-Z]{2}",
                            "type": "string",
                            "description": "TestDescription \n Line2 TestDescription"
                        }
                    }
                }
            }
        }
    }
}   

But The Ascii Output is always written in one line

[cols="2,3,1,1,1"] .Query Parameters |=== |Name| Description| Required| Default| Pattern

| testName | TestDescription Line2 TestDescription | X | null | /^(([a-z]{2}[A-Z]{2})+,){0,9}([a-z]{2}[A-Z]{2}){1}$/

|===