对于未答复的请求,我想隐藏此字段(模型架构)。
我的要求
@ApiOperation(value = "Create node")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "body", required = true)
})
public Result insert()
我不想在@ApiOperation 中显示 response 属性。有可能吗?
谢谢!
我不确定你在问什么。但是,如果您尝试在 JSON 响应中隐藏模型中的特定字段,请尝试使用 fastxml 的 jackson-annotations 模块中的
JsonIgnore
注释。只需将注释添加到您在响应中试图避免的字段即可。
即使您没有说,根据您在 https://github.com/swagger-api/swagger-play/pull/76#issuecomment-224287765 上的帖子,我相信您正在使用 Play Framework。我相信目前 swagger-play 中的“void”结果已被破坏(参考: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 _ => ()
}
}
}
}
}
}
隐藏所有控制器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;
}