Java SpringWebFlux/Mono或作为返回的Flux对象的OpenAPI CodeGen
最新版本的OpenApi Codegen(及其Maven插件)能够/应该能够使用Webflux/Creative返回对象(例如Mono或Flux对象)为spring Maven自动生成接口。然而,我看不出它能起作用。 以下是my pom.xml的摘录:Java SpringWebFlux/Mono或作为返回的Flux对象的OpenAPI CodeGen,java,spring,mono,reactive,openapi,Java,Spring,Mono,Reactive,Openapi,最新版本的OpenApi Codegen(及其Maven插件)能够/应该能够使用Webflux/Creative返回对象(例如Mono或Flux对象)为spring Maven自动生成接口。然而,我看不出它能起作用。 以下是my pom.xml的摘录: <plugin> <groupId>io.swagger</groupId> <artifactId>swagger-codegen-maven-plugin
<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>
和自动生成的身份验证接口:
@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);
}
@ApiOperation(value=”,昵称=“getDotcmsAuthentication”,notes=“返回带有JWT令牌的dotCMS json”,response=UserAuthentication.class,标记={“authentication”,“dotCMS”,})
@ApiResponses(值={
@ApiResponse(code=200,message=“成功验证”,response=UserAuthentication.class),
@ApiResponse(代码=400,消息=“错误请求错误”),
@ApiResponse(code=401,message=“格式不正确的身份验证头”)}
@请求映射(value=“/dotcmsAuthentication”,
生成={“应用程序/json”},
使用={“应用程序/json”},
method=RequestMethod.GET)
默认响应属性getDotcmsAuthentication(@ApiParam(value=”“,required=true)@RequestHeader(value=“DotcmsAuthentication”,required=true)字符串DotcmsAuthentication){
if(getObjectMapper().isPresent()和&getAcceptHeader().isPresent()){
if(getAcceptHeader().get()包含(“应用程序/json”)){
试一试{
返回新的ResponseEntity(getObjectMapper().get().readValue(“{\”jwtToken\“:\”jwtToken\“}”,UserAuthentication.class),HttpStatus.NOT\实现);
}捕获(IOE异常){
错误(“无法序列化内容类型应用程序/json的响应”,e);
返回新的响应属性(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}否则{
log.warn(“默认AuthenticationApi接口中未配置ObjectMapper或HttpServletRequest,因此未生成示例”);
}
返回新的响应状态(HttpStatus.NOT_IMPLEMENTED);
}
现在,主要的问题是:如何让openapi codegen生成MONO和Flux对象,而不是这些ResponseEntity对象
如果你需要知道任何其他细节来帮助我,请告诉我,我会提供它们。谢谢。您的YAML文件无效,它混合使用了OpenAPI 2.0和3.0语法。粘贴到以查找并修复语法错误,然后重试。@Helen虽然这不是问题的全部,但它仍然使我走上了正确的道路。我还必须将
io.swagger-swagger-codegen-maven-plugin${swagger.codegen.version}
更改为org.openapitools-openapi-generator-maven-plugin 3.3.3
,而且,我似乎无法正确格式化此评论--你能正常工作吗?如果是这样的话,我需要一些帮助well@Schenz您需要在openapi生成器maven插件的
中设置true
@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);
}