gpt4 book ai didi

java - 阐明 Swagger - 使用泛型时无法生成文档资源模型

转载 作者:太空宇宙 更新时间:2023-11-04 14:33:58 29 4
gpt4 key购买 nike

我面临着与该线程中描述的类似的问题:

Can Enunciate generate docs for an API that handles generic types?

我正在使用 enunciate 1.28,并启用了 spring 和 swagger 模块。

因此考虑像这样的抽象资源类:

public abstract class AbstractResource<T> {

@Autowired
private SomeService<T> service;

@Path("/{id}")
@GET
public T get(@PathParam("id") String id) {
return service.get(id);
}

@POST
public Response post(T entity) {
return service.post(entity);
}
}

以及一个具体实现:

@Path("/authors")
public class AuthorResource extends AbstractResource<Author> { }
  1. 阐明文档不是使用 GET 和 POST 方法的正确“作者”数据模型生成的。

对于 GET 我有:

Response Body element:  (custom)`

并发布:

Request Body element: entity`
  • 对于 Swagger,Author 模型未显示为 GET 作为“responseClass”和 POST 作为正文“dataType”的 JSON 模型。相反,我得到了两者的字符串。
  • 但是,Author 模型列在 swagger/ui 目录中生成的 AuthorResource.json 中。 responseClass 和 dataType 字段只是缺少模型的链接。

    手动替换:

    "responseClass" : "string"` by `"responseClass" : "ns0_Author" (GET)
    "dataType" : "string"` by `"dataType" : "ns0_Author" (POST)

    成功了。

    注意:我确认 Author 是用 @XmlRootElement 注释的,并且 Author 类包含在我的 <api-import pattern="com.my.package.**"/> 中。它位于类路径上的 jar 文件中。

    关于在这种情况下如何调整 Enunciate/Swagger 文档生成有什么想法吗?

    谢谢

    最佳答案

    闻起来像 bug 。追踪它 here .

    关于java - 阐明 Swagger - 使用泛型时无法生成文档资源模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25814560/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com