[英]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
然后在
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>
With swagger-springmvc ( https://github.com/springfox/springfox ) at the moment there's no way to use SwaggerSpecFilter.使用 swagger-springmvc ( https://github.com/springfox/springfox ) 目前无法使用 SwaggerSpecFilter。 But it respects @ApiIgnore annotation - it can be applied to method parameter which shouldn't appear in generated metadata.
但它尊重 @ApiIgnore 注释 - 它可以应用于不应出现在生成的元数据中的方法参数。
如果您使用io.swagger.v3
,则应使用@Parameter(hidden = true)
, @Parameter(hidden = true)
处https://springdoc.org/migrating-from-springfox.html迁移指南中所述
注释@ApiParam(hidden = true)
为我解决了问题。
def myFunc(@ApiParam(hidden = true) i: Int) = {...}
In sprigfox-swagger2
implementation there is an annotation @ApiModelProperty
that does this.在
sprigfox-swagger2
实现中,有一个注释@ApiModelProperty
可以做到这一点。
Example:例子:
@ApiModelProperty(required = false, hidden = true)
private String internallyUsedProperty;
此答案使用.ignoredParameterTypes
或@ApiIgnore
描述了 springfox 中的当前解决方案
You could annotate your fields with:您可以使用以下方法注释您的字段:
@Schema(description = "foo bar.", required = false, hidden = true, example = "bar")
private String fooDtoField
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.