2016-06-07 4 views
0

요청에 답하지 않으려면이 필드 (모델 스키마)를 숨기고 싶습니다.Swagger에서 스키마 모델을 숨기려면 어떻게해야합니까?

my swagger

내 요청 나는 @ApiOperation에서 응답 속성을 보여주고 싶지 않아

@ApiOperation(value = "Create node") 
@ApiImplicitParams({ 
     @ApiImplicitParam(paramType = "body", required = true) 
}) 
public Result insert() 

. 있을 수있다?

감사합니다!

+0

은 당신이 지금까지 시도 않았다 : 한 가지 방법 내가 (스칼라)를했다가 @ApiOperation에서 responseReference = "void"를 제공하고 내 변화를 재정의 할 자신감 사양을 보여 내 스칼라 컨트롤러로 다음 작업을 수행 할 수 있었다? 문제가 무엇입니까? SO가 어떻게 작동하는지 더 잘 이해하려면 둘러보기 : http://stackoverflow.com/tour를 방문하십시오. – Pilatus

+0

잘 모르겠습니다. 코드 나 스크린 샷에 '응답'속성이 표시되지 않습니다. 콘텐츠가 어떻게 보이길 기대합니까? – kenske

답변

0

당신이 무엇을 요구하고 있는지 잘 모르겠습니다. 그러나 JSON 응답에서 모델의 특정 필드를 숨기려고하면 fasterxml의 jackson-annotations 모듈에서 JsonIgnore 주석을 사용해보십시오. 응답에서 피하려고하는 필드에 주석을 추가하기 만하면됩니다.

0

비록 당신이 말하지 않더라도, 나는 귀하의 게시물 인 플레이 프레임 워크를 사용하고있는 https://github.com/swagger-api/swagger-play/pull/76#issuecomment-224287765에 기반을 두었습니다. 나는 현재 무용담으로 "무효"한 결과가 나왔다고 믿는다 (ref : https://github.com/swagger-api/swagger-play/issues/89).

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 _ =>() 
      } 
     } 
     } 
    } 
    } 
}