Description
When a parameter's OpenAPI schema has a default value containing the
sequence */ (e.g. an Accept header defaulting to */*), the generated
Java client's @param Javadoc line embeds that value raw and unescaped,
which prematurely closes the enclosing /** ... */ comment block and
produces a Java file that fails to compile.
openapi-generator version
7.25.0 (also reproduces on other recent versions - the relevant template
code is unchanged on master as of this writing)
Java (client) generator
Steps to reproduce
- Minimal OpenAPI 3.1 spec with a header parameter defaulting to
*/*:
```yaml
openapi: 3.1.0
info:
title: repro
version: "1.0"
paths:
/ping:
get:
operationId: ping
parameters:
- name: Accept
in: header
required: false
schema:
type: string
default: "/"
examples: ["application/json", "text/plain", "/"]
responses:
"200":
description: ok
```
-
Generate:
```
docker run --rm -v $(pwd):/spec -v /tmp/out:/output
openapitools/openapi-generator-cli:v7.25.0 generate
--input-spec /spec/repro.yaml --generator-name java --output /output
```
-
Compile the generated client (e.g. mvn compile).
Actual behavior
Compilation fails. The generated @param line reads:
```
- @PARAM accept (optional, default to /)
```
The */ inside that text closes the Javadoc block early, so every line
after it in the same comment becomes invalid Java source.
Expected behavior
The generated client should compile. defaultValue (and any other
free-text value interpolated into a Javadoc comment) should go through
comment-safe escaping, the same way consumes/produces content types
are handled via escapeText() in addConsumesInfo (see #10598, which
is the same underlying class of bug in the other direction).
Related
Description
When a parameter's OpenAPI schema has a
defaultvalue containing thesequence
*/(e.g. an Accept header defaulting to*/*), the generatedJava client's
@paramJavadoc line embeds that value raw and unescaped,which prematurely closes the enclosing
/** ... */comment block andproduces a Java file that fails to compile.
openapi-generator version
7.25.0 (also reproduces on other recent versions - the relevant template
code is unchanged on master as of this writing)
Java (client) generator
Steps to reproduce
*/*:```yaml
openapi: 3.1.0
info:
title: repro
version: "1.0"
paths:
/ping:
get:
operationId: ping
parameters:
- name: Accept
in: header
required: false
schema:
type: string
default: "/"
examples: ["application/json", "text/plain", "/"]
responses:
"200":
description: ok
```
Generate:
```
docker run --rm -v $(pwd):/spec -v /tmp/out:/output
openapitools/openapi-generator-cli:v7.25.0 generate
--input-spec /spec/repro.yaml --generator-name java --output /output
```
Compile the generated client (e.g.
mvn compile).Actual behavior
Compilation fails. The generated
@paramline reads:```
```
The
*/inside that text closes the Javadoc block early, so every lineafter it in the same comment becomes invalid Java source.
Expected behavior
The generated client should compile.
defaultValue(and any otherfree-text value interpolated into a Javadoc comment) should go through
comment-safe escaping, the same way
consumes/producescontent typesare handled via
escapeText()inaddConsumesInfo(see #10598, whichis the same underlying class of bug in the other direction).
Related
Java/libraries/okhttp-gson/api.mustache,the
{{#defaultValue}}, default to {{.}}{{/defaultValue}}line -{{.}}only gets Mustache's HTML-entity escaping, not Java-commentescaping.