openapi-generator
openapi-generator copied to clipboard
[BUG][Java] @Tag description should merge multiple lines into single line and trim the newline char at the end
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [ ] Have you validated the input using an OpenAPI validator (example)?
- [ ] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
openapi-generator version
6.0.0
OpenAPI declaration file content or url
https://newpathfly.ticketcombine.com/openapi.yaml
pay attention to following lines:
tags:
- name: Shopping
description: |
Search for virtual interlining offerings of cheapest flights.
Generation Details
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.0.0</version>
<executions>
<execution>
<id>1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.newpathfly.api</apiPackage>
<modelPackage>com.newpathfly.model</modelPackage>
<configOptions>
<dateLibrary>java8</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<openApiNullable>false</openApiNullable>
<serializableModel>true</serializableModel>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
-
git clone https://github.com/newpathfly/newpathfly-public-api
- update
openapi-generator-maven-plugin
to6.0.0
- run
mvn clean package
- look at the
ShoppingApi.java
as example in thegenerated-sources
undertarget
folder
Actual:
There is a newline at the end of the tag description:
@Tag(name = "shopping", description = "Search for virtual interlining offerings of cheapest flights.
")
Expect:
There should not be any newline at the end of the tag description:
@Tag(name = "shopping", description = "Search for virtual interlining offerings of cheapest flights.")
Related issues/PRs
Suggest a fix
Hello, just to notice that I'm facing the same issue.
Workaround would be using block chomping indicator strip -
to strip new line at the end.
You could also use block scalar style folded >
to replace new lines with spaces.
By declaring your Tag as following:
tags:
- name: Shopping
description: >-
Search for virtual interlining offerings of cheapest flights.
Hey there,
this also happens if you use \n
within a json definition:
"tags": [
{
"name": "groups",
"description": "**Current Group Roles**: \n\nROLE1 - User may do stuff 1 \n\nROLE2 - User may do other stuff \n\nROLE3 - User may even more stuff \n\n"
}
]
This will generate broken Tag
annotations with line breaks within the description
of the tag.
@Tag(name = "Groups", description = "**Current Group Roles**:
ROLE1 - User may do stuff 1
ROLE2 - User may do other stuff
ROLE3 - User may even more stuff
")
This happens in 6.0.1
Sadly in this case the Yaml workarounds do not work.
This issue still seems to be relevant in 6.2.1 version, or am I missing something?
Any update on this issue? I can not use the work around as I do not maintain the open api spec we are trying to consume.
It would be great to introduce a new Lambda which changes all new lines with \n
Something like:
public class ReplaceNewLineLambda implements Mustache.Lambda {
@Override
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
String text = fragment.execute();
writer.write(text.replaceAll("\n", "\\\\n"));
}
}
and usage is:
@Tag(name = "{{{tagName}}}", description = {{#tagDescription}}"{{#lambda.replaceNewLine}}{{{.}}}{{/lambda.replaceNewLine}}"{{/tagDescription}}{{^tagDescription}}"the {{{tagName}}} API"{{/tagDescription}})
Hi, some Mustache.Lambda
already exists in SpringCodegen.java
such as lambdaEscapeDoubleQuote
and lambdaRemoveLineBreak
.
(modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java:683)
In api.mustache
, maybe just replacing
{{#tagDescription}}"{{{.}}}"{{/tagDescription}}
with
{{#tagDescription}}"{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{.}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}"{{/tagDescription}}
would fix the issue ?
(modules/openapi-generator/src/main/resources/JavaSpring/api.mustache:87)