dwickern / sbt-swagger-play

sbt plugin for swagger-play
MIT License
12 stars 2 forks source link

In plugin missed call for SwaggerSpecFilter #11

Open Villy21 opened 2 years ago

Villy21 commented 2 years ago

Swagger-play did not support @ApiParam(hidden = true) so I implemented parameter hide with SwaggerSpecFilter src and details But in SwaggerRunner -> SwaggerPluginImpl this plugin miss to call swaggerPlugin.swaggerSpecFilter from original Swagger ApiHelpController

So in plugin mode Swagger-play did not run SwaggerSpecFilter. It load filter class but did not call f.filter(specs, filter, queryParams.asJava, cookies, headers)

So the only case to use SwaggerSpecFilter is to use original Swagger-play

Original function from ApiHelpController

protected def getApiListing(resourceName: String, host: String)(implicit requestHeader: RequestHeader): Swagger = {
    Logger("swagger").debug("ApiHelpInventory.getResource(%s)".format(resourceName))
    val f = new SpecFilter
    val queryParams = requestHeader.queryString.map {case (key, value) => key -> value.toList.asJava}
    val cookies = requestHeader.cookies.map {cookie => cookie.name -> cookie.value}.toMap.asJava
    val headers = requestHeader.headers.toMap.map {case (key, value) => key -> value.toList.asJava}.asJava
    val pathPart = resourceName

    val specs = swaggerPlugin.apiListingCache.listing(host)

    val clone = swaggerPlugin.swaggerSpecFilter match {
      case Some(filter) => f.filter(specs, filter, queryParams.asJava, cookies, headers)
      case None => specs
    }
    clone.setPaths(clone.getPaths.asScala.filter(_._1.startsWith(pathPart)).asJava)
    clone
  }