spring - 将 swagger-maven-plugin 集成到 Spring 应用程序中

标签 spring swagger

我很难尝试将 Swagger 合并到我的 Spring 应用程序中。我试图生成 .json文件使用 com.github.kongchen:swagger-maven-plugin:3.1.0io.swagger:swagger-core:1.5.0用于注释,但生成的文件完全是空的:

{
  "swagger" : "2.0",
  "info" : {
    "version" : "v1",
    "title" : "KVS"
  }
}

Controller 示例

@RestController
@Api(
    tags = { "k/v" },
    value = "Main microservice entrypoint",
    produces = "application/json",
    consumes = "application/json",
    protocols = "http,https"
)
class AbcController {
    @ApiOperation(value = "/")
    @ApiResponses({
        @ApiResponse(code = 200, message = "Request entry", response = KvsEntry.class),
        @ApiResponse(code = 404, message = "Entry not found", response = Void.class)
    })
    @RequestMapping(value = "/", method = RequestMethod.POST)
    public ResponseEntity<KvsEntry> create(@Validated @RequestBody KvsEntry kvsEntry) {
        kvsEntry = keyValueService.saveEntry(kvsEntry);
        return new ResponseEntity<>(kvsEntry, HttpStatus.OK);
    }
}

我仍然可以使用 <springmvc>false</springmvc> 获得一些结果配置和 JAX-RS 注释(我想说,不太正确),但这会适得其反。我可能做错了什么?

最佳答案

请检查此存储库上带有 Spring MVC 注释的工作插件的简单示例:

https://github.com/khipis/swagger-maven-example

插件对依赖项版本以及是否存在特定注释很敏感。

关于spring - 将 swagger-maven-plugin 集成到 Spring 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31807676/

相关文章:

java - 如何为@RequestParam 的默认值提供表达式

java - 未创建审核表

azure - 为 Azure Functions 启用 Swagger(OpenAPI 2.0 元数据)

spring-boot - 如何更改<主机 :port> to domain in swagger

java - 如果使用 WebMvcConfigurationSupport 添加转换器,Swagger OpenAPI 3 不会在 springboot 2 上显示

swagger - NestJs Swagger如何添加自定义图标

java - 无法使用可嵌入 ID 创建新实体

java - Spring JTA TransactionManager 配置 : Supporting both Tomcat and JBoss

java - 将 application.properties 传递给 Logback 自定义过滤器

swagger - swagger 的多态性未按预期工作