2014-12-23 4 views
3

저는 Swagger JaxRs의 현재 마스터 1.0과 Swagger 2.0의 devel_2.0 브랜치를 사용해 보았습니다.Swagger JaxRS가 판별 자로 ApiModel 상속을 할 수 있습니까?

@ApiModel(value = "Animal", 
    subTypes = {Dog.class, Lion.class}, 
    discriminator = "type") 
public class Animal { 

    @ApiModelProperty(value = "the discriminator field.") 
    private String type; 

그리고 여기가

@ApiModel(value = "Lion", parent = Animal.class) 
public class Lion { 

@ApiModelProperty(value = "the discriminator field.") 
private String type; 

내가 무엇을 기대해야하는지 어떤 많은 예를 찾을 수없는 한 하위 클래스 중 하나이지만, 여기에 내 현재의 자신감 2.0 프로젝트 swagger.json의 출력 파일.

"definitions":{ 
     "Animal":{ 
     "properties":{ 
      "type":{ 
       "type":"string", 
       "description":"the discriminator field." 
      } 
     }, 
     "discriminator":"type" 
     }, 

정의 아래에있는 개 또는 사자 개체의 기호가 없습니다. 요청 개체에 아무것도 없습니다. 작동하면 어떻게 될지 모르겠지만 어떻게 작동하는지 알고 있다면 알려주십시오.

전체 코드를 보려면 여기를 클릭하십시오.

https://github.com/javatestcase/RestEasy/tree/RestEasyVersion2

+1

어떻게 샘플을 실행합니까? 나는 그것을 부두에서 직접 실행하려고 노력하고있다. 분명히 pom에 RESTEasy 의존성이 없기 때문에 (Swagger 2 브랜치를 보면) 분명히 작동하지 않는다. – Ron

+0

@webron - Jetty 또는 Tomcat을 빠르게 실행할 수 없었지만 wildfly-maven-plugin을 포함했습니다. jetty plugin -> http : // localhost : 8080/RestEasy-1/xyz/swagger.json과 같은 방식으로 실행할 수 있어야합니다. – javatestcase

+0

고마워, 나는 그것을 단지 체크 아웃 하겠지만, 아마 내일 뿐이다. 늦었 어. – Ron

답변

3

귀하의 예를 많이 도와주었습니다, 그래서 내가 지금 일하고 있어요 때문에 나는 수익에 도움이해야한다고 생각!

당신은 어떻게 구현을 바인딩 직렬화/deserialisation 말할 필요

:

@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME, // Were binding by providing a name 
    include = JsonTypeInfo.As.PROPERTY, // The name is provided in a property 
    property = "type", // Property name is type 
    visible = true // Retain the value of type after deserialisation 
) 
@JsonSubTypes({//Below, we define the names and the binding classes. 
    @JsonSubTypes.Type(value = Lion.class, name = "Lion"), 
    @JsonSubTypes.Type(value = Dog.class, name = "Dog") 
}) 
@ApiModel(value = "Animal", subTypes = {Dog.class, Lion.class}, discriminator = "type") 
public class Animal { 
관련 문제