Open Villy21 opened 2 years ago
"swagger-play2.8" % "3.1.0" did not support @ApiParam(hidden = true) so I implemented parameter hide with SwaggerSpecFilter.
[WARN] SwaggerSpecFilter work only in this swagger-play but not with sbt-swagger-play plugin because of Issue 11.
To use SwaggerSpecFilter to hide parameters:
package filters; import io.swagger.core.filter.AbstractSpecFilter; import io.swagger.model.ApiDescription; import io.swagger.models.Operation; import io.swagger.models.parameters.Parameter; import play.Logger; import java.util.List; import java.util.Map; public class InternalSwaggerFilter extends AbstractSpecFilter { protected final Logger.ALogger logger = Logger.of("swagger"); @Override public boolean isParamAllowed(Parameter parameter, Operation operation, ApiDescription api, Map<String, List<String>> params, Map<String, String> cookies, Map<String, List<String>> headers) { String access = parameter.getAccess(); if ((access != null) && access.equals("hidden")) { logger.debug(String.format("InternalSwaggerFilter:isParamAllowed %s %s parameter:%s access=hidden -> false", operation.getOperationId() ,api.getPath() ,parameter.getName())); return false; } return true; } }
swagger.filter="filters.InternalSwaggerFilter" play.modules.enabled += "play.modules.swagger.SwaggerModule"
@ApiParam(access = "hidden")
Like:
@Api(value = "Base Api", produces = "application/json") public class APIController extends Controller { @Path("/users") @ApiOperation( tags={ "user" }, value = "Get users list." ) public CompletionStage<Result> getUsersList( @ApiParam(access = "hidden") Http.Request request){ return getList(request, User.class); } }
libraryDependencies ++= Seq( // API annotations "io.swagger" % "swagger-annotations" % "1.6.6", "io.swagger" % "swagger-core" % "1.6.6", // The following is only necessary if you're having trouble resolving dependencies "javax.ws.rs" % "jsr311-api" % "1.1.1", "com.github.dwickern" %% "swagger-play2.8" % "3.1.0", "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.11.1" )
"swagger-play2.8" % "3.1.0" did not support @ApiParam(hidden = true) so I implemented parameter hide with SwaggerSpecFilter.
[WARN] SwaggerSpecFilter work only in this swagger-play but not with sbt-swagger-play plugin because of Issue 11.
To use SwaggerSpecFilter to hide parameters:
@ApiParam(access = "hidden")
to hide parameters you not need.Like: