mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 14:40:53 +00:00
Improve generation of README which has long description (#400)
* Add `appDescriptionWithNewLines` * Add test case for escapeText as well * Ruby client allows new lines in README * Add doc comment * fix issue related to github web gui * the case of no description provided * Run `./bin/utils/ensure-up-to-date` https://app.shippable.com/github/OpenAPITools/openapi-generator/runs/1118/1/console
This commit is contained in:
parent
dcc0c17a29
commit
0137763997
@ -75,6 +75,8 @@ public interface CodegenConfig {
|
|||||||
|
|
||||||
String escapeText(String text);
|
String escapeText(String text);
|
||||||
|
|
||||||
|
String escapeTextWhileAllowingNewLines(String text);
|
||||||
|
|
||||||
String escapeUnsafeCharacters(String input);
|
String escapeUnsafeCharacters(String input);
|
||||||
|
|
||||||
String escapeReservedWord(String name);
|
String escapeReservedWord(String name);
|
||||||
|
@ -414,6 +414,31 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
.replace("\"", "\\\""));
|
.replace("\"", "\\\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape characters while allowing new lines
|
||||||
|
*
|
||||||
|
* @param input String to be escaped
|
||||||
|
* @return escaped string
|
||||||
|
*/
|
||||||
|
public String escapeTextWhileAllowingNewLines(String input) {
|
||||||
|
if (input == null) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove \t
|
||||||
|
// replace \ with \\
|
||||||
|
// replace " with \"
|
||||||
|
// outter unescape to retain the original multi-byte characters
|
||||||
|
// finally escalate characters avoiding code injection
|
||||||
|
return escapeUnsafeCharacters(
|
||||||
|
StringEscapeUtils.unescapeJava(
|
||||||
|
StringEscapeUtils.escapeJava(input)
|
||||||
|
.replace("\\/", "/"))
|
||||||
|
.replaceAll("[\\t]", " ")
|
||||||
|
.replace("\\", "\\\\")
|
||||||
|
.replace("\"", "\\\""));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* override with any special text escaping logic to handle unsafe
|
* override with any special text escaping logic to handle unsafe
|
||||||
* characters so as to avoid code injection
|
* characters so as to avoid code injection
|
||||||
|
@ -216,9 +216,11 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
// set a default description if none if provided
|
// set a default description if none if provided
|
||||||
config.additionalProperties().put("appDescription",
|
config.additionalProperties().put("appDescription",
|
||||||
"No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)");
|
"No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)");
|
||||||
|
config.additionalProperties().put("appDescriptionWithNewLines", config.additionalProperties().get("appDescription"));
|
||||||
config.additionalProperties().put("unescapedAppDescription", "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)");
|
config.additionalProperties().put("unescapedAppDescription", "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)");
|
||||||
} else {
|
} else {
|
||||||
config.additionalProperties().put("appDescription", config.escapeText(info.getDescription()));
|
config.additionalProperties().put("appDescription", config.escapeText(info.getDescription()));
|
||||||
|
config.additionalProperties().put("appDescriptionWithNewLines", config.escapeTextWhileAllowingNewLines(info.getDescription()));
|
||||||
config.additionalProperties().put("unescapedAppDescription", info.getDescription());
|
config.additionalProperties().put("unescapedAppDescription", info.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
{{moduleName}} - the Ruby gem for the {{appName}}
|
{{moduleName}} - the Ruby gem for the {{appName}}
|
||||||
|
|
||||||
{{#appDescription}}
|
{{#appDescriptionWithNewLines}}
|
||||||
{{{appDescription}}}
|
{{{appDescriptionWithNewLines}}}
|
||||||
{{/appDescription}}
|
{{/appDescriptionWithNewLines}}
|
||||||
|
|
||||||
This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
||||||
|
|
||||||
|
@ -235,6 +235,33 @@ public class DefaultCodegenTest {
|
|||||||
Assert.assertNotNull(type);
|
Assert.assertNotNull(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEscapeText() {
|
||||||
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
|
||||||
|
Assert.assertEquals(codegen.escapeText("\n"), " ");
|
||||||
|
Assert.assertEquals(codegen.escapeText("\r"), " ");
|
||||||
|
Assert.assertEquals(codegen.escapeText("\t"), " ");
|
||||||
|
Assert.assertEquals(codegen.escapeText("\\"), "\\\\");
|
||||||
|
Assert.assertEquals(codegen.escapeText("\""), "\\\"");
|
||||||
|
Assert.assertEquals(codegen.escapeText("\\/"), "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEscapeTextWhileAllowingNewLines() {
|
||||||
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
|
||||||
|
// allow new lines
|
||||||
|
Assert.assertEquals(codegen.escapeTextWhileAllowingNewLines("\n"), "\n");
|
||||||
|
Assert.assertEquals(codegen.escapeTextWhileAllowingNewLines("\r"), "\r");
|
||||||
|
|
||||||
|
// escape other special characters
|
||||||
|
Assert.assertEquals(codegen.escapeTextWhileAllowingNewLines("\t"), " ");
|
||||||
|
Assert.assertEquals(codegen.escapeTextWhileAllowingNewLines("\\"), "\\\\");
|
||||||
|
Assert.assertEquals(codegen.escapeTextWhileAllowingNewLines("\""), "\\\"");
|
||||||
|
Assert.assertEquals(codegen.escapeTextWhileAllowingNewLines("\\/"), "/");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateCodegenPropertyEnum() {
|
public void updateCodegenPropertyEnum() {
|
||||||
final DefaultCodegen codegen = new DefaultCodegen();
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user