Swagger-ui не показывает контрольную документацию

Я пытаюсь использовать 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("[email protected]")
                .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

Я не очень хорошо знаком с этой конфигурацией. Есть идеи по правильной конфигурации?

Спасибо


person rasilvap    schedule 15.05.2019    source источник


Ответы (1)


Попробуйте заменить значение 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()
}
  • Значение по умолчанию для swagger path - /v2/api-docs.

    Вы можете изменить это в application.properties с помощью клавиши springfox.documentation.swagger.v2.path на все, что захотите.

  • ?group=api-infos происходит от значения .groupName("api-infos").

    Если вы не хотите группировать свои API по каким-либо причинам (например, наборы выбранных API для определенных клиентов), удалите .groupName(...).

person Vladas Maier    schedule 16.05.2019