5

The newest Version of OpenApi Codegen (and it's Maven plugin) are/should be able to auto-generate interfaces for spring maven with Webflux/Reative return objects (e.g. Mono or Flux objects). Yet, I don't see to be able to get it working. These are excerpts from my pom.xml:

    <plugin>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-codegen-maven-plugin</artifactId>
        <version>${swagger.codegen.version}</version>
        <executions>
        <!-- AUTHENTICATION-API -->
            <execution>
              <id>authentication-api</id>
              <goals>
                <goal>generate</goal>
              </goals>
              <configuration>
                <inputSpec>src/main/resources/swagger/authentication.yaml</inputSpec>
                <language>spring</language>
                <configOptions>
                  <sourceFolder>src/main/java</sourceFolder>
                    <library>spring-boot</library>
                    <!-- <async>true</async> -->
                    <reactive>true</reactive>
                    <dateLibrary>java8</dateLibrary>
                    <useTags>true</useTags>
                    <apiPackage>${project.groupId}.api</apiPackage>
                    <modelPackage>${project.groupId}.model</modelPackage>
                    <interfaceOnly>true</interfaceOnly>
                </configOptions>
              </configuration>
            </execution>
         </executions>
</plugin>

And these are excerpts from the authentication.yaml and the generated interface

authentication.yaml

paths:
  /dotcmsAuthentication:
    get:
      tags:
        - authentication
        - dotCMS
      description: Returns dotCMS json with JWT Token.
      operationId: getDotcmsAuthentication
      produces:
        - application/json
      consumes:
        - application/json
      parameters:
        - name: DotcmsAuthentication
      in: header
          required: true
          schema:
            type: string
            example: '{"user":"username", "password":"password"}'
      responses:
        '200':
          description: Successful authentication
          schema:
            $ref: '#/definitions/UserAuthentication'
        '401':
          description: Malformed authentication header
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MalformedAuthenticationHeaderError'
        '400':
          description: BAD_REQUEST error
          content:
            application/json:
              schema:
                 $ref: '#/components/schemas/RequestError'

and auto-generaten authentication interface:

@ApiOperation(value = "", nickname = "getDotcmsAuthentication", notes = "Returns dotCMS json with JWT Token.", response = UserAuthentication.class, tags={ "authentication","dotCMS", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "Successful authentication", response = UserAuthentication.class),
    @ApiResponse(code = 400, message = "BAD_REQUEST error"),
    @ApiResponse(code = 401, message = "Malformed authentication header") })
@RequestMapping(value = "/dotcmsAuthentication",
    produces = { "application/json" }, 
    consumes = { "application/json" },
    method = RequestMethod.GET)
default ResponseEntity<UserAuthentication> getDotcmsAuthentication(@ApiParam(value = "" ,required=true) @RequestHeader(value="DotcmsAuthentication", required=true) String dotcmsAuthentication) {
    if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
        if (getAcceptHeader().get().contains("application/json")) {
            try {
                return new ResponseEntity<>(getObjectMapper().get().readValue("{  \"jwtToken\" : \"jwtToken\"}", UserAuthentication.class), HttpStatus.NOT_IMPLEMENTED);
            } catch (IOException e) {
                log.error("Couldn't serialize response for content type application/json", e);
                return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
            }
        }
    } else {
        log.warn("ObjectMapper or HttpServletRequest not configured in default AuthenticationApi interface so no example is generated");
    }
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}

Now, the main question is: How do i get the openapi-codegen to generate MONO and Flux Objects instead of these ResponseEntity Objects?

If you need to know any other details to help me, please just tell me, and i will provide them. Thanks.

J. Schaefer
  • 81
  • 1
  • 1
  • 2
  • Your YAML file is not valid, it uses a mix of OpenAPI 2.0 and 3.0 syntax. Paste it into http://editor.swagger.io to find & fix syntax errors, then try again. – Helen Nov 25 '18 at 15:41
  • @Helen while that wasn't the whole problem, it still put me on the right path. I also had to change `io.swagger swagger-codegen-maven-plugin ${swagger.codegen.version}` to `org.openapitools openapi-generator-maven-plugin 3.3.3` also, i seem to be unable to format this comment properly -.- – J. Schaefer Nov 27 '18 at 11:20
  • did you get this working? If so I could use some help as well – Schenz Feb 07 '19 at 16:45
  • 6
    @Schenz you need to set `true` in `` of `openapi-generator-maven-plugin` – petronius Nov 19 '19 at 13:47

0 Answers0