scala 如何在swagger中隐藏参数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22812365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 06:09:47  来源:igfitidea点击:

How to hide a parameter in swagger?

scalarestswagger

提问by eugen-fried

did anyone succeed to hide a parameter from generated documentation? I found an issue here, but using @ApiParam(access="internal", required=false)before @HeaderParamdid not seem to work.

有没有人成功地从生成的文档中隐藏参数?我在这里发现了一个问题,但@ApiParam(access="internal", required=false)之前使用@HeaderParam似乎不起作用。

采纳答案by eugen-fried

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>

回答by Ronny Shibley

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

回答by Paul Lysak

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.

使用 swagger-springmvc ( https://github.com/springfox/springfox) 目前无法使用 SwaggerSpecFilter。但它尊重 @ApiIgnore 注释 - 它可以应用于不应出现在生成的元数据中的方法参数。

回答by magiccrafter

In sprigfox-swagger2implementation there is an annotation @ApiModelPropertythat does this.

sprigfox-swagger2实现中,有一个注释@ApiModelProperty可以做到这一点。

Example:

例子:

@ApiModelProperty(required = false, hidden = true)
private String internallyUsedProperty;

回答by Vasyl Yamnych

Annotation @ApiParam(hidden = true)resolved issue for me.

注释@ApiParam(hidden = true)为我解决了问题。

def myFunc(@ApiParam(hidden = true) i: Int) = {...}

回答by gogstad

Thisanswer describes the current solution in springfox using .ignoredParameterTypesor @ApiIgnore

答案描述了 springfox 中使用.ignoredParameterTypes或的当前解决方案@ApiIgnore