简体   繁体   English

用Swagger进行发音-使用泛型时无法生成文档资源模型

[英]Enunciate with Swagger - cannot generate documentation resource models when using generics

I'm facing similar issue than the one described in that thread : 我面临的问题与该线程中描述的问题类似:

Can Enunciate generate docs for an API that handles generic types? Enunciuncate可以为处理通用类型的API生成文档吗?

I am using enunciate 1.28 with spring and swagger modules enabled. 我正在使用启用了spring和swagger模块的enunciate 1.28。

So considering an abstract resource class like : 因此,考虑一个抽象资源类,例如:

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);
    }
}

and one concrete implementation : 和一个具体的实现:

@Path("/authors")
public class AuthorResource extends AbstractResource<Author> { }
  1. Enunciate docs are not generated with the proper "Author" Data Model for both GET and POST methods. GET和POST方法均未使用正确的“作者”数据模型生成清晰的文档。

For GET I have : 对于GET我有:

Response Body element:  (custom)`

and POST : 和POST:

Request Body element: entity`
  1. For Swagger the Author model is not showing as the JSON model for GET as "responseClass" and POST for the body "dataType". 对于Swagger,作者模型未显示为GET和JSON的JSON模型,分别为“ responseClass”和主体的“ dataType”。 Instead I get string for both. 相反,我都得到了字符串。

However the Author model is listed in the AuthorResource.json generated in swagger/ui directory. 但是Author模型在swagger / ui目录中生成的AuthorResource.json中列出。 The responseClass and dataType fields are just missing the link to the model. responseClass和dataType字段仅缺少指向模型的链接。

Manually replacing : 手动更换:

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

does the trick. 绝招。

Note : I confirm that on my side Author is annotated with @XmlRootElement and the Author class is included in my <api-import pattern="com.my.package.**"/> which is located in a jar file on the classpath. 注意:我确认我这一边的作者用@XmlRootElement注释,并且Author类包含在我的<api-import pattern="com.my.package.**"/> ,该文件位于类路径的jar文件中。

Any ideas on how to tweak the Enunciate/Swagger documentation generation in that case ? 在这种情况下,如何调整Enunciate / Swagger文档生成的任何想法?

Thanks 谢谢

Smells like a bug. 闻起来像臭虫。 Tracking it here . 在这里跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM