fix(kotlin-server): emit KDoc for operation summary and description in jaxrs-spec interfaces - #24810
Conversation
There was a problem hiding this comment.
1 issue found across 5 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiInterface.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiInterface.mustache:14">
P3: In the new @return block, {{message}} uses double-stache, which HTML-escapes the value, while summary, notes, and @param descriptions in this same change use triple-stache {{{...}}} and the Java template renders messages with {{{message}}}. A response message containing &, <, or > will be emitted literally as &, <, etc. in the generated KDoc. Use {{{message}}} for consistency and correct output. (By default the Mustache renderer escapes {{ }} content.)</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| {{/description}} | ||
| {{/allParams}} | ||
| {{#responses.0}} | ||
| * @return {{#responses}}{{message}} (status code {{code}}){{^-last}} |
There was a problem hiding this comment.
P3: In the new @return block, {{message}} uses double-stache, which HTML-escapes the value, while summary, notes, and @PARAM descriptions in this same change use triple-stache {{{...}}} and the Java template renders messages with {{{message}}}. A response message containing &, <, or > will be emitted literally as &, <, etc. in the generated KDoc. Use {{{message}}} for consistency and correct output. (By default the Mustache renderer escapes {{ }} content.)
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiInterface.mustache, line 14:
<comment>In the new @return block, {{message}} uses double-stache, which HTML-escapes the value, while summary, notes, and @param descriptions in this same change use triple-stache {{{...}}} and the Java template renders messages with {{{message}}}. A response message containing &, <, or > will be emitted literally as &, <, etc. in the generated KDoc. Use {{{message}}} for consistency and correct output. (By default the Mustache renderer escapes {{ }} content.)</comment>
<file context>
@@ -1,3 +1,43 @@
+ {{/description}}
+ {{/allParams}}
+ {{#responses.0}}
+ * @return {{#responses}}{{message}} (status code {{code}}){{^-last}}
+ * or {{/-last}}{{/responses}}
+ {{/responses.0}}
</file context>
| * @return {{#responses}}{{message}} (status code {{code}}){{^-last}} | |
| * @return {{#responses}}{{{message}}} (status code {{code}}){{^-last}} |
…n jaxrs-spec interfaces The kotlin-server jaxrs-spec apiInterface template emitted only the JAX-RS annotations, so an interfaceOnly API interface carried no documentation at all for its operations. The equivalent Java template (JavaJaxRS/spec) has always emitted a Javadoc block, and the models generated by this same library already carry KDoc, so the API interfaces were the odd ones out. Emit a KDoc block built from the operation summary and notes, with @PARAM for documented parameters and @return listing the responses. The @return formatting follows the kotlin-server javalin6 templates so the output is consistent across the generator. The block is omitted entirely when an operation has neither a summary nor notes, rather than emitting an empty comment. The body shared by the summary and notes branches lives in an operationDoc partial so the two do not drift. File form parameters are documented under the name formParams.mustache actually generates for them, which appends an InputStream suffix. Fixes OpenAPITools#24794
|
Thanks — all three were fair, and the first one was a real bug. Fixed in the amended commit.
* @param {{paramName}}{{#isFormParam}}{{#isFile}}InputStream{{/isFile}}{{/isFormParam}} {{{description}}}
Duplicated body across the two branches. Agreed. The shared portion now lives in a new One implementation note on the partial, in case it comes up: the partial has to carry its own indentation with the /**
* uploads an image
* @param petId ID of pet to update
* @return successful operation (status code 200)Samples regenerated. Apart from the |
bfe912a to
0a85fbb
Compare
Fixes #24794.
The
kotlin-serverjaxrs-specapiInterface.mustachetemplate emitted only the JAX-RS annotations, so aninterfaceOnly: trueAPI interface carried no documentation for its operations at all. The equivalent Java template (JavaJaxRS/spec/apiInterface.mustache) has always emitted a Javadoc block, and the models generated by this same library already carry KDoc, so the API interfaces were the odd ones out.Change
A KDoc block built from the operation
summaryandnotes, with@paramfor documented parameters and@returnlisting the responses.Two details worth flagging for review:
@returnformatting follows thekotlin-serverjavalin6templates (successful operation (status code 200)/or ...) rather than the Java template's{{#responses}}@return {{{message}}}{{/responses}}, which emits one@returnline per response. This keeps the output consistent within the Kotlin generator and valid as KDoc./** */. The Java template emits its block unconditionally.@paramis only emitted for parameters that actually have a description, so undocumented parameters do not produce a bare@param nameline.Generated output
Before:
@GET @Path("/findByStatus") @Produces("application/xml", "application/json") fun findPetsByStatus(@QueryParam("status") status: kotlin.collections.List<kotlin.String>): io.smallrye.mutiny.Uni<Response>After:
Samples
Regenerated with
./bin/generate-samples.shfor the fourkotlin-server-jaxrs-spec*configs. Only the two that setinterfaceOnlyproduce output changes, since the others generate throughapiMethod.mustache:samples/server/others/kotlin-server/jaxrs-spec-array-responsesamples/server/petstore/kotlin-server/jaxrs-spec-mutinyNote
apiMethod.mustachein the same library has the same gap for the non-interfaceOnlycase. I left it out to keep this change scoped to the reported issue — happy to follow up separately, or fold it in here if you would prefer.PR checklist
Summary by cubic
Fixes #24794 by emitting KDoc on operation methods in
kotlin-serverjaxrs-specinterfaces wheninterfaceOnlyis set, so generated API docs match the Java generator and model KDoc. Previously these interfaces had no method documentation.@paramfor described parameters, and@returnlisting responses.apiMethod.mustacheis out of scope.Written for commit 0a85fbb. Summary will update on new commits.