我正在尝试使用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("Swager 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>)
当我加载Pickle Cython Class with C pointers(摇摆浏览器)时。我看不到我的控制器结构。似乎有一个预先定义的端点whihc显示:
http://localhost:8080/swagger-ui.html#/api-controller
我对这种配置不太熟悉。对正确配置有任何想法吗?
谢谢
答案 0 :(得分:0)
尝试将paths
的值替换为PathSelectors.any()
:
@Bean
open fun newsApi() : Docket {
return Docket(DocumentationType.SWAGGER_2)
.groupName("api-infos")
.apiInfo(apiInfo())
.directModelSubstitute(LocalDateTime::class.java, Date::class.java)
.select()
.paths(PathSelectors.any())
.build()
}
摇摇路径的默认值为/v2/api-docs
。
您可以使用application.properties
键在springfox.documentation.swagger.v2.path
中更改您想要的内容。
?group=api-infos
来自.groupName("api-infos")
值。
如果您出于任何原因(例如为特定客户端选择的API集)不希望对API进行分组,请删除.groupName(...)
。