对于未答复的请求,我想隐藏此字段(模型架构)。
我的要求
@ApiOperation(value = "Create node")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "body", required = true)
})
public Result insert()
我不想在@ApiOperation中显示响应属性。它有可能吗?
谢谢!
答案 0 :(得分:0)
我不确定你在问什么。但是,如果您尝试在JSON响应中隐藏模型中的特定字段,请尝试使用fastxml的jackson-annotations模块中的$ ./test
$ echo $?
0
$
注释。只需将注释添加到您在响应中尝试避免的字段中。
答案 1 :(得分:0)
即使您没有说,我相信您在https://github.com/swagger-api/swagger-play/pull/76#issuecomment-224287765发布的帖子表明您正在使用Play Framework。我相信目前招摇的“无效”结果已被打破(参考:https://github.com/swagger-api/swagger-play/issues/89)。我在Scala中执行此操作的一种方法是在responseReference = "void"
中提供@ApiOperation
并执行以下操作作为我的Scala控制器,以显示Swagger规范以覆盖我的更改:
package controllers
import controllers.SwaggerBaseApiController
import io.swagger.models.auth.{ApiKeyAuthDefinition, BasicAuthDefinition, In}
import io.swagger.models.properties.RefProperty
import io.swagger.models.{Info, Response}
import play.api.mvc.Action
import scala.collection.JavaConversions._
object Swagger extends SwaggerBaseApiController {
def json = Action { implicit request =>
val swagger = getResourceListing(request.host)
// We need to modify this if it doesn't contain our security definitions yet, but we have to do it atomically
// This should be fast enough that this synchronization is not too bad
swagger.synchronized {
if (!somethingThreadSafeToShowYouveChangedItAlready) fixSwagger(swagger)
}
// We trust that the above code only changes a swagger instance once therefore we don't need to
// synchronize the json marshalling because it should not change beneath it
returnValue(request, toJsonString(swagger))
}
private[this] def fixSwagger(swagger: io.swagger.models.Swagger): Unit = {
// Omitted some of my other changes...
swagger.getPaths.values.foreach { value =>
value.getOperations.foreach { oper =>
// Omitted some of my other chabnges
// Any responses that are void need to be simple void
oper.getResponses.values.foreach { resp =>
resp.getSchema() match {
case schema: RefProperty if schema.get$ref() == "#/definitions/void" => resp.setSchema(null)
case _ => ()
}
}
}
}
}
}
答案 2 :(得分:0)
隐藏所有控制器API
@ApiIgnore
隐藏所选属性
@ApiModelProperty(required = false, hidden = true)
示例:可见
@ApiModelProperty(
access = "public",
name = "amount",
example = "123.45",
value = "the amount - in this example without currency.")
public String getAmount() {
return amount;
}
示例:隐藏
@ApiModelProperty(
required = false,
hidden = true
)
public String getAmount() {
return amount;
}