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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
回答2:
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>
回答3:
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.
回答4:
In sprigfox-swagger2
implementation there is an annotation @ApiModelProperty
that does this.
Example:
@ApiModelProperty(required = false, hidden = true)
private String internallyUsedProperty;
回答5:
Annotation @ApiParam(hidden = true)
resolved issue for me.
def myFunc(@ApiParam(hidden = true) i: Int) = {...}
回答6:
This answer describes the current solution in springfox using .ignoredParameterTypes
or @ApiIgnore