Swotger为Kotlin

有没有人用Kotlin使用了一个夸大的工具?

在我们的组织中,我们使用Java和SpringMVC(@RestController类)创建了大部分REST服务。 我们使用springfox来生成Swagger API文档。 Swagger JSON表示也用于自动提供可搜索的服务目录,所以服务元数据的swagger格式对我们来说非常重要。

一些开发团队现在开始使用Kotlin。 我们正在寻找与使用KOTLIN的springfox或其他swagger库有关的建议或意见。

这里是示例spring启动应用程序与招摇:

@RestController class MyController { @ApiOperation(value = "doc header...", notes = "detailed doc...") @RequestMapping(value = "/double", method = arrayOf(RequestMethod.GET)) fun doubleValue(number: Int) = 2 * number } @Configuration @EnableSwagger2 class SwaggerConfig { @Bean fun api(): Docket { return Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build() } } 

依赖关系是

 compile("io.springfox:springfox-swagger2:2.7.0") compile("io.springfox:springfox-swagger-ui:2.7.0") 

如果您浏览http:// localhost:8080 / swagger-ui.html,那么所有…

我最近有一个类似的要求。 因此,我创建了一个集成了Kotlin,Webflux和Swagger的模板项目 。 它提供交互式API文档和自动请求validation。

看到这里 – > https://github.com/cdimascio/kotlin-swagger-spring-functional-template

validation是有效的。 它是这样使用的:

 validate.request(req) { // Do stuff eg return a list of names ok().body(Mono.just(listOf("carmine", "alex", "eliana"))) } 

与身体

 validate.request(req).withBody(User::class.java) { body -> // Note that body is deserialized as User! // Now you can do stuff. // For example, lets echo the request as the response ok().body(Mono.just(body)) } 

它利用atlassian提供的v2 swaggervalidation。