我正在尝试使用 springfox-swagger-ui 来记录我的休息服务。我在 kotlin 项目中使用了下一个基本配置:
这是我的 Docket 课程:
@Configuration
@EnableSwagger2
open class SwaggerConfig {
@Bean
open fun newsApi(): Docket {
return Docket(DocumentationType.SWAGGER_2)
.groupName("api-infos")
.apiInfo(apiInfo())
.directModelSubstitute(LocalDateTime::class.java, Date::class.java)
.select()
.paths(regex("/api.*"))
.build()
}
private fun apiInfo(): ApiInfo {
return ApiInfoBuilder()
.title("Infos REST api")
.description("Swagger test for Api ESPN")
.termsOfServiceUrl("http://en.wikipedia.org/wiki/Terms_of_service")
.contact("rodolfo.silva@globant.com")
.license("Apache License Version 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
.version("1.0")
.build()
}
}
这是我的控制器:
@Controller
@ProductApi(
id = "v1_browse_player",
title = "Browse Player (v1)",
description = "")
@Api(value = "controller", description = "Controllers API", produces = "application/json")
@RequestMapping("/api/infos")
class BrowsePlayerController {
@Autowired
lateinit var browsePlayerService: BrowsePlayerServiceRepresentable
@GetRequest(
path = "/v1/browse/players",
timeToLive = 300,
queries = [
QueryParameter(name = "swid", required = true),
QueryParameter(name = "uid"),
QueryParameter(name = "seeAll", type = java.lang.Boolean::class),
QueryParameter(name = "lang", required = true),
QueryParameter(name = "region", required = true),
QueryParameter(name = "version", required = true, type = Integer::class),
QueryParameter(name = "appName", required = true),
QueryParameter(name = "platform", required = true)
]
)
@ApiOperation(value = "Get the players", notes = "Returns one info for playerBrowse")
fun processBrowsePlayerRequest(transaction: Transaction, apiRequest: ApiRequest): Single<BrowsePlayerResponse?> {
val applicationContext = RequestBasedApplicationContext(apiRequest)
val standardContext = RequestBasedStandardContext(
RequestBasedVersionContext(apiRequest),
applicationContext,
RequestBasedEditionContext(apiRequest, applicationContext),
RequestBasedPlatformContext(apiRequest),
transaction
)
val swidContext = RequestBasedSWIDContext(apiRequest)
val uidContext = if (checkUIDPresent(apiRequest)) RequestBasedUIDContext(apiRequest) else null
val seeAllContext = RequestBasedSeeAllContext(apiRequest)
val requestBrowsePlayerContext = RequestBrowsePlayerContext(standardContext, swidContext, uidContext, seeAllContext, apiRequest)
return browsePlayerService.getEntitiesBrowse(requestBrowsePlayerContext)
}
private fun checkUIDPresent(apiRequest: ApiRequest): Boolean =
apiRequest.parameters["uid"] != null
}
我使用了一个非常基本的配置,即 ApiOperation、Api 和 RequestMapping("/api/infos") 标签,也是在数据类级别,下一个配置:
@JsonInclude(JsonInclude.Include.NON_NULL)
data class TopBrowsePlayerHeader(val title: String, val searchURL: String?)
@ApiModel(value = "Info entity", description = "Entity class BrowsePlayerResponse")
data class BrowsePlayerResponse(
@ApiModelProperty(value = "The header of the info", required = false)
val header: TopBrowsePlayerHeader,
@ApiModelProperty(value = "The analytics node of the info", required = true)
val analytics: Analytics,
@ApiModelProperty(value = "The sections node of the info", required = true)
val sections: List<Section>)
当我加载http://localhost:8080/swagger-ui.html#/api-controller(招摇浏览器)。我看不到我的控制器结构。似乎有一个预定义的端点,如下所示:
http://localhost:8080/v2/api-docs?group=api-infos
我对这个配置不是很熟悉。对正确配置有什么想法吗?
谢谢