2017-12-12 2 views
0

다음 두 엔티티 클래스가 있습니다.다른 jar 파일에있는 엔티티 클래스에서 ApiModel 및 ApiModelProperty 주석을 검색하지 않습니다.

제 클래스 SampleApiEntity이다

package my.company.rest; 

import io.swagger.annotations.ApiModel; 
import io.swagger.annotations.ApiModelProperty; 
import org.hibernate.annotations.Type; 
import java.io.Serializable; 
import java.sql.Timestamp; 
import java.util.UUID; 
import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.Id; 

@ApiModel (
    value  = "SampleApiEntity", 
    description = "This is a sample entity from the Api package." 
) 
@Entity 
public class SampleApiEntity 
     implements Serializable 
{ 
    public SampleApiEntity() {} 

    private static final long serialVersionUID = 1L; 

    @Column (nullable = false) 
    @ApiModelProperty (
     value = "level", 
     required = true 
    ) 
    private Integer level; 

    @Column (length = 255) 
    @ApiModelProperty (
     value = "description" 
    ) 
    private String description; 

    @Column (nullable = false) 
    @ApiModelProperty (
     value = "time", 
     required = true 
    ) 
    private Timestamp time; 

    @Id 
    @Column (
     unique = true, 
     nullable = false 
    ) 
    @Type (type = "pg-uuid") 
    @ApiModelProperty (
     value = "id", 
     readOnly = true, 
     dataType = "uuid", 
     example = "123e4567-e89b-12d3-a456-426655440000" 
    ) 
    private UUID  sampleApiEntityId; 

    public String getDescription() 
    { 
     return this.description; 
    } 

    public Integer getLevel() 
    { 
     return this.level; 
    } 

    public UUID getSampleApiEntityId() 
    { 
     return this.sampleApiEntityId; 
    } 

    public Timestamp getTime() 
    { 
     return this.time; 
    } 

    public void setDescription (String description) 
    { 
     this.description = description; 
    } 

    public void setLevel (Integer level) 
    { 
     this.level = level; 
    } 

    public void setSampleApiEntityId (UUID sampleApiEntityId) 
    { 
     this.sampleApiEntityId = sampleApiEntityId; 
    } 

    public void setTime (Timestamp time) 
    { 
     this.time = time; 
    } 
} 

번째 클래스 SampleModelEntity이다

package my.company.model; 

import io.swagger.annotations.ApiModel; 
import io.swagger.annotations.ApiModelProperty; 
import org.hibernate.annotations.Type; 
import java.io.Serializable; 
import java.sql.Timestamp; 
import java.util.UUID; 
import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.Id; 

@ApiModel (
    value  = "SampleModelEntity", 
    description = "This is a sample entity from the Model package." 
) 
@Entity 
public class SampleModelEntity 
     implements Serializable 
{ 
    public SampleModelEntity() {} 

    private static final long serialVersionUID = 1L; 

    @Column (nullable = false) 
    @ApiModelProperty (
     value = "level", 
     required = true 
    ) 
    private Integer level; 

    @Column (length = 255) 
    @ApiModelProperty (
     value = "description" 
    ) 
    private String description; 

    @Column (nullable = false) 
    @ApiModelProperty (
     value = "time", 
     required = true 
    ) 
    private Timestamp time; 

    @Id 
    @Column (
     unique = true, 
     nullable = false 
    ) 
    @Type (type = "pg-uuid") 
    @ApiModelProperty (
     value = "id", 
     readOnly = true, 
     example = "123e4567-e89b-12d3-a456-426655440000" 
    ) 
    private UUID  sampleModelEntityId; 

    public String getDescription() 
    { 
     return this.description; 
    } 

    public Integer getLevel() 
    { 
     return this.level; 
    } 

    public UUID getSampleModelEntityId() 
    { 
     return this.sampleModelEntityId; 
    } 

    public Timestamp getTime() 
    { 
     return this.time; 
    } 

    public void setDescription (String description) 
    { 
     this.description = description; 
    } 

    public void setLevel (Integer level) 
    { 
     this.level = level; 
    } 

    public void setSampleModelEntityId (UUID sampleModelEntityId) 
    { 
     this.sampleModelEntityId = sampleModelEntityId; 
    } 

    public void setTime (Timestamp time) 
    { 
     this.time = time; 
    } 
} 

두 클래스 간의 유일한 차이점은 이들이 별개의 JAR 파일에 정의되어있다. SampleApiEntity은 REST 자원 클래스와 동일한 JAR에 패키지되어 있습니다. SampleModelEntity은 다른 엔티티 클래스와 별도의 JAR에 패키지되어 있습니다. 생성 된 swagger.yaml 파일은 두 클래스를 모두 포함하지만 SampleModelEntity 클래스의 ApiModelApiModelProperty 주석에 의해 제공된 정보가 부족합니다.

SampleApiEntity: 
    type: "object" 
    required: 
    - "level" 
    - "time" 
    properties: 
    level: 
     type: "integer" 
     format: "int32" 
     description: "level" 
    description: 
     type: "string" 
     description: "description" 
    time: 
     type: "string" 
     format: "date-time" 
     description: "time" 
    sampleApiEntityId: 
     type: "string" 
     format: "uuid" 
     example: "123e4567-e89b-12d3-a456-426655440000" 
     description: "id" 
     readOnly: true 
    description: "This is a sample entity from the Api package." 
SampleModelEntity: 
    type: "object" 
    properties: 
    level: 
     type: "integer" 
     format: "int32" 
    description: 
     type: "string" 
    time: 
     type: "string" 
     format: "date-time" 
    sampleModelEntityId: 
     type: "string" 
     format: "uuid" 

사람은 ApiModelApiModelProperty 주석 swagger.yaml에서 출력을 생성하지 않는 이유를 내가 이해하는 데 도움이 : 여기

내가 생성 된 swagger.yaml 파일에보고하고 무엇인가?

+0

내가 어떤 연구를하고있다 그리고 나는 아래로 좁혀했습니다 발행물. 이 문제는'SampleModelEntity' 클래스가 REST 리소스 클래스와는 별도의 JAR에 패키지되어 있다는 사실 때문에 간단히 나타나지는 않습니다. REST 리소스 패키지의 pom.xml 파일에서'SampleModelEntity'를 포함하는 종속성 JAR이'제공된 '범위로 선언됩니다. 범위가 문제의 원인 인 것 같습니다. –

답변

0

해결책을 찾았습니다. 클래스 로딩 문제로 밝혀졌습니다. war 라이브러리를 배포하는 데 사용했던 ear 라이브러리가 있습니다. warear에는 swagger-annotations 이슈의 사본이 포함되어 있습니다. 이로 인해로드 된 주석 클래스는 ear에 패키지 된 클래스와 다릅니다.

pom.xml 파일을 war 라이브러리로 수정하여 문제를 해결했습니다. 나는 명시 적 의존성과 자신감 - 주석을 추가하고, provided으로 그 범위를 설정 : 당신은 여기서 더 많은 정보를 찾을 수 있습니다

<dependency> 
     <groupId>io.swagger</groupId> 
     <artifactId>swagger-annotations</artifactId> 
     <version>1.5.10</version> 
     <scope>provided</scope> 
    </dependency> 

가 : https://github.com/swagger-api/swagger-core/issues/2582

관련 문제