How to hide a parameter in swagger?
Hope this helps.
For Fields
@ApiModelProperty(required = false, hidden = true)
private String hiddenProperty
For Apis
@ApiIgnore
public class MyApi {}
For Parameters
public void getApi(@ApiIgnore String param){}
@ApiModelProperty(hidden="true")
public String paramInsideClass
Ok, looking at the unit tests helped. First you need to define a filter:
import com.wordnik.swagger.core.filter.SwaggerSpecFilter
import com.wordnik.swagger.model.{Parameter, ApiDescription, Operation}
import java.util
class MySwaggerSpecFilter extends SwaggerSpecFilter{
override def isOperationAllowed(operation: Operation, api: ApiDescription, params: util.Map[String, util.List[String]], cookies: util.Map[String, String], headers: util.Map[String, util.List[String]]): Boolean = true
override def isParamAllowed(parameter: Parameter, operation: Operation, api: ApiDescription, params: util.Map[String, util.List[String]], cookies: util.Map[String, String], headers: util.Map[String, util.List[String]]): Boolean = {
if(parameter.paramAccess == Some("internal")) false
else true
}
}
And then enable it in web.xml
<servlet>
<servlet-name>DefaultJaxrsConfig</servlet-name>
<servlet-class>com.wordnik.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
...
<init-param>
<param-name>swagger.filter</param-name>
<param-value>com.example.MySwaggerSpecFilter</param-value>
</init-param>
</servlet>
If you are using io.swagger.v3
, you should use @Parameter(hidden = true)
as described on the migration guide here https://springdoc.org/migrating-from-springfox.html
With swagger-springmvc (https://github.com/springfox/springfox) at the moment there's no way to use SwaggerSpecFilter. But it respects @ApiIgnore annotation - it can be applied to method parameter which shouldn't appear in generated metadata.