首页 文章

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

提问于
浏览
1

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

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

我正在使用启用 spring 和swagger模块的enunciate 1.28 .

所以考虑一个抽象资源类,如:

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> { }
  • 对于GET和POST方法,不使用正确的"Author"数据模型生成Enunciate文档 .

对于GET,我有:

Response Body element:  (custom)`

和POST:

Request Body element: entity`
  • 对于Swagger,作者模型未显示为GET的JSON模型为"responseClass",而POST为主体"dataType" . 相反,我得到两个字符串 .

但是,作者模型列在swagger / ui目录中生成的AuthorResource.json中 . responseClass和dataType字段只是缺少模型的链接 .

手动更换:

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

诀窍 .

注意:我确认在我这一边作者用@XmlRootElement注释,而Author类包含在我的 <api-import pattern="com.my.package.**"/> 中,它位于类路径的jar文件中 .

在这种情况下如何调整Enunciate / Swagger文档生成的任何想法?

谢谢

1 回答

  • 0

    闻起来像个臭虫 . 跟踪它here .

相关问题