用于Spring-Webflux / Mono或Flux对象的OpenAPI CodeGen作为返回

时间:2018-11-25 12:28:33

标签: java spring mono reactive openapi

最新版本的OpenApi Codegen(及其Maven插件)应该/能够使用Webflux / Reative返回对象(例如Mono或Flux对象)自动生成Spring Maven接口。但是,我认为它无法正常工作。 这些是我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>

这些是来自authentication.yaml和生成的接口的摘录

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'

和自动生成的身份验证界面:

@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);
}

现在,主要问题是:如何获取openapi-codegen来生成 MONO和Flux 对象,而不是这些 ResponseEntity 对象?

如果您需要其他任何帮助的细节,请告诉我,我会提供。谢谢。

0 个答案:

没有答案