Swagger 不扫描位于不同 jar 文件中的实体类中的 ApiModel 和 ApiModelProperty 注释

2024-01-07

我有以下两个实体类。

第一堂课是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生成的文件包含这两个类,但缺少由ApiModel and ApiModelProperty的注释SampleModelEntity class.

这是我在生成的内容中看到的swagger.yaml file:

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"

有人可以帮助我理解为什么ApiModel and ApiModelProperty注释没有生成输出swagger.yaml?


我找到了解决方案。原来是类加载问题。我有一个ear我用来部署的库war图书馆。这俩warear包含一份 swagger-annotations 工件的副本。这导致加载的注释类与包装中的注释类不同ear.

我通过修改我的解决了这个问题pom.xml文件为war图书馆。我将 swagger-annotations 添加为显式依赖项,并将其范围设置为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 https://github.com/swagger-api/swagger-core/issues/2582

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Swagger 不扫描位于不同 jar 文件中的实体类中的 ApiModel 和 ApiModelProperty 注释 的相关文章

随机推荐

  • Vbscript列出文件夹和子文件夹中的所有PDF文件

    好吧 这是我的代码 但我无法使用 objFile Extension 过滤列表 我确信这很愚蠢 Set objFSO CreateObject Scripting FileSystemObject objStartFolder C dev
  • 了解 Vulkan 统一布局的“集合”索引

    我一直在关注 非常棒的 nvpro 光线追踪教程 并且对使用 CameraProperties 统一缓冲区的绑定方式有疑问layout binding 0 set 1 我理解绑定 0 但为什么设置 1 教程中说 set 1来自以下事实 它是
  • 导入错误:没有名为 cv2.cv 的模块

    python 3 5 和 Windows 10 我使用以下命令安装了 open cv pip install opencv python 3 1 0 cp35 cp35m win amd64 whl 这个命令在 python 中工作正常 i
  • 是否有与 git archive 相反的命令用于导入 zip 文件

    在主要修订正式纳入 大 公司 SCM 系统之前 我们的本地工作流程倾向于使用一系列 zip 文件作为本地 源代码控制 我正在尝试引入 git 作为一种更好的本地 SCM 方法 当前的工作流程对于我们的小团队来说非常有效 特别是当测试机器离线
  • Visual Studio 2015 中缺少 Xamarin 空白应用程序(本机)模板

    我已经在 Visual Studio 2015 中安装了使用 Xamarin 进行开发的所有工具 但不知何故 当我创建新项目时 我没有看到空白应用程序 本机 模板 我只能使用空白应用程序 Xamarin Forms 模板 我已经尝试重新安装
  • 如何对 Symfony2 控制器进行单元测试?

    我想尽可能多地使用测试驱动开发 这是一种很好的工作方式 我对 Symfony2 控制器创建并返回一个新的事实感到困扰Response object 我希望能够对控制器进行单独的单元测试 你怎么做呢 答案是创建一个控制器作为普通旧 PHP 对
  • SQL Server 更改计算列

    有谁知道如何更改计算列而不删除 SQL Server 中的列 我想停止使用该列作为计算列并开始直接在列中存储数据 但希望保留当前值 这可能吗 据我所知 但这是你可以做的事情 添加另一列到表中 使用计算列的值更新该列 然后删除计算列
  • 使用 Python 将 BMP/PNG/JPEG 转换为 SVG 文件

    我目前正在尝试使用 Python 将 BMP 文件转换为 SVG 文件 我正在尝试找到一个 Python 库 使我能够将 BMP PNG JPEG 文件转换为 SVG 文件 我已经尝试过使用 Potrace 但质量很糟糕 我需要相当高质量的
  • 不同文件夹中的文件具有相同的命名空间

    我正在尝试构建一个项目 以便自动生成的一些代码位于子文件夹中generated 但它与父目录中的文件具有相同的命名空间 例如 我有这个结构 它给了我错误PHP Fatal error Uncaught Error Class MyProje
  • 将文本字符串中的任何 url 替换为可单击的 php 链接

    假设我有一串文本 例如 text Hello world be sure to visit http whatever com today 我如何 可能使用正则表达式 插入链接的锚标记 将链接本身显示为链接文本 您可以使用正则表达式来执行此
  • 检测颜色并从图像中删除该颜色

    我的图像背景为浅紫色图像 字符为深蓝色 我的目标是从图像中识别文本 所以我试图从背景中删除浅紫色 以便我的图像没有噪音 但我找不到该图像的确切颜色代码 因为它在各处都有些不同 所以我无法遮盖图像 这是我的代码 import numpy as
  • 构建自引用元组

    在看到多年前的论坛上的一次从未解决的对话后 我想知道如何正确创建一个引用自身的元组 从技术上讲 这是一个非常糟糕的主意 因为元组应该是不可变的 一个不可变的对象怎么可能包含它自己呢 然而 这个问题不是关于最佳实践 而是关于 Python 中
  • setInterval 在 Chrome 上无法正常工作

    我有一个定制的幻灯片对象来执行名称在网站上指示的常见操作 一切正常 除非我在 Chrome 中切换选项卡并返回网站选项卡 当这种情况发生时 幻灯片就会变得疯狂并开始淡化图像 而不管setInterval给定的间隔 找不到与此相关的任何内容
  • 按字母顺序选择排序程序的问题

    我遇到了涉及选择排序概念的家庭作业问题 我们得到了一个框架代码 我们需要在其中完成bool compare and void selectionsort 功能 我已经完成了 然后 运行程序应该对给出的字符串进行排序main 按字母顺序排列
  • Windows cmd git bash:conda.sh没有这样的文件或目录(Windows行结尾,缺少斜杠)

    我正在 Windows 10 中工作 全新安装了 Anaconda 和 Git Bash 我决定将 cmd exe 设置为默认控制台程序以使用 git bash 而不是 minTTY 并且我认为我已经遇到了 Unix 风格字符与 Windo
  • 在matlab中使用FFT去除图像中的图案和噪声

    我使用 clown jpg 图像来消除其明显的图案 噪音 在对图像进行 FFT 之前所做的第一步是将其重新调整为 2 次幂的方形图像 即 256 x 256 在 matlab 中使用 FFT 和 fftshift 可以实现快速傅里叶变换 其
  • 使用 webpack 生成多个 html 文件

    我正在尝试在一个项目中做一些我不确定是否可能的事情 我的方式错误或误解了某些事情 我们正在使用 webpack 其想法是提供多个 html 文件 本地主机 8181 gt 提供index html本地主机 8181 example html
  • 为什么系统类方法无法访问?

    您好 我对 java 有点陌生 正在尝试从 txt 文件中提取字符串 BufferedReader br new BufferedReader new FileReader file txt try StringBuilder sb new
  • 将 OCaml 字符串转换为 format6

    以下代码无法编译 let x hello in Printf printf x 错误是 Error This expression has type string but an expression was expected of type
  • Swagger 不扫描位于不同 jar 文件中的实体类中的 ApiModel 和 ApiModelProperty 注释

    我有以下两个实体类 第一堂课是SampleApiEntity package my company rest import io swagger annotations ApiModel import io swagger annotati