OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA][Spring][Server] Javadoc error in generated controller with delegate pattern

Open
#8,290 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

Javadoc fail in generated controller with delegate pattern :

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.0.0:jar (attach-javadocs) on project myapi: MavenReportException: Error while generating Javadoc:
[ERROR] Exit code: 1 - ...\target\generated-sources\openapi\src\gen\java\main\com\myapi\controllers\HelloApiController.java:13: error: annotation type not applicable to this kind of declaration
[ERROR]     public HelloApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) HelloApiDelegate delegate) {
[ERROR]
[ERROR] Command line was: ...oracle-jdk.11.0.1-x64\bin\javadoc.exe @options @packages
[ERROR]
[ERROR] Refer to the generated Javadoc files in '...\target\apidocs' dir.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

This is cause by @org.springframework.beans.factory.annotation.Autowired(required = false) :

public HelloApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) HelloApiDelegate delegate) {
...
}
openapi-generator version

5.0.0

OpenAPI declaration file content or url
openapi: 3.0.3

info:
  title: myapi
  version: 1.0.0

paths:
  /hello:
    get:
      tags:
        - hello-controller
      summary: test
      operationId: hello
      parameters:
        - name: message
          in: query
          description: a message
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/hello'
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '500':
          description: Internal Server Error
      deprecated: false

security:
  - jwtAuthentication: []

components:
  securitySchemes:
    jwtAuthentication:
      description: This API supports JWT Authentication with bearer token.
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    hello:
      type: object
      properties:
        message:
          type: string
      required:
        - message
Generation Details
                    <plugin>
                           <groupId>org.openapitools</groupId>
                           <artifactId>openapi-generator-maven-plugin</artifactId>
                           <version>5.0.0</version>
                           <executions>
                                  <execution>
                                        <id>server</id>
                                        <goals>
                                               <goal>generate</goal>
                                        </goals>
                                        <configuration>
                                              <inputSpec>${project.basedir}/src/main/resources/contract/${project.artifactId}.yaml</inputSpec>
                                               <generatorName>spring</generatorName>
                                               <modelNameSuffix>DTO</modelNameSuffix>
                                               <configOptions>
                                                      <title>${project.artifactId}</title>
                                                      <sourceFolder>src/gen/java/main</sourceFolder>
                                                      <library>spring-boot</library>
                                                      <useTags>false</useTags>
                                                      <serializableModel>true</serializableModel>
                                                      <swaggerDocketConfig>true</swaggerDocketConfig>
                                                      <delegatePattern>true</delegatePattern>
                                                      <dateLibrary>java8</dateLibrary>
                                                      <apiPackage>com.myapi.controllers</apiPackage>
                                                      <modelPackage>com.myapi.model</modelPackage>
                                                      <invokerPackage>com.myapi.invoker</invokerPackage>
                                               </configOptions>
                                        </configuration>
                                  </execution>
                           </executions>
                    </plugin>
Steps to reproduce

Generate server with spring (and delegate pattern option) and then launch javadoc.

Suggest a fix

Generate something like that (?) :

@org.springframework.beans.factory.annotation.Autowired
public HelloApiController(HelloApiDelegate delegate) {
...
}

(this is what swagger-codegen-v3 do for example)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue by generating a Spring server with delegatePattern enabled from the supplied OpenAPI document, then run Maven Javadoc generation. Trace the Spring generator's delegate-pattern template that produces HelloApiController and compare the generated constructor annotation with the reported form. Done means generated sources pass Javadoc generation without the annotation error, with regression coverage if the generator's existing tests provide a suitable place.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.