2017-12-12 7 views
0

私は以下の2つのエンティティクラスを持っています。別の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クラスのApiModelおよびApiModelPropertyアノテーションによって提供される情報が欠けています。ここで

は私が生成さswagger.yamlファイルで見ていますものです:

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で出力を生成していない理由を私は理解するのに役立つことはできますか?

+0

を私はいくつかの研究を行ってきたと私は絞り込まれてきました問題。この問題は、 'SampleModelEntity'クラスがRESTリソースクラスとは別のJARにパッケージされているという事実だけでは発生していないようです。 RESTリソースパッケージのpom.xmlファイルには、 'SampleModelEntity'を含む依存関係JARが'提供された 'スコープで宣言されています。スコープが原因で問題が発生しているようです。 –

答えて

0

解決策が見つかりました。それはクラスロードの問題であることが判明しました。 warライブラリを展開するために使用していたearライブラリがありました。 warearには、スワッガーアノテーションアーティファクトのコピーが含まれていました。その結果、読み込まれた注釈クラスは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

関連する問題