Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide a parameter in swagger?

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.

like image 536
eugen-fried Avatar asked Apr 02 '14 13:04

eugen-fried


People also ask

How do I hide query parameters in Swagger?

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.

How do I hide a field in Swagger?

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.

How do you make parameter optional in Swagger?

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.

How do I hide Swagger method?

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.


2 Answers

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
like image 107
Ronny Shibley Avatar answered Sep 18 '22 23:09

Ronny Shibley


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>
like image 22
eugen-fried Avatar answered Sep 19 '22 23:09

eugen-fried