did anyone succeed to hide a parameter from generated documentation? I found an issue here, but using @ApiParam(access="internal", required=false)
before @HeaderParam
did not seem to work.
6. Using @ApiParam. @ApiParam is also a Swagger annotation that we can use to specify metadata related to request parameters. We can set the hidden property to true in order to hide any property.
This is all you need to add to hide the field in the Swagger ui: @ApiModelProperty(hidden = true) private List<Reservation> reservations; That would hide the reservation list from showing. Save this answer.
Required and Optional Parameters By default, Swagger treats all request parameters as optional. You can add required: true to mark a parameter as required. Note that path parameters must have required: true , because they are always required. description: Numeric ID of the user to get.
By adding this attribute on a controller or action and specifying IgnoreApi = true , it gets hidden from auto-generated documentation. However, this user has to apply this to around 80 controllers.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With