从现有的 REST api 生成 Swagger 文档文档、REST、api、Swagger

2023-09-08 09:24:46 作者:消逝

给定一个现有的带有 JAX-RS 注释的 API,它接受 &返回带有杰克逊注释类型的json,有没有办法可以生成一些YAML Swagger文档?我的计划 B 是编写一些代码,使用反射来查找带​​有 REST 注释的类型,制作它们的参数的哈希图 &返回,然后为 Jackson 注释爬取这些类,并以这种方式生成文档.

Given an existing JAX-RS-annotated API that accepts & returns json, with jackson-annotated types, is there a way that I can generate some YAML Swagger documentation? My plan B is to write some code that uses reflection to find REST-annotated types, make a hashmap of their arguments & returns, and then crawl those classes for Jackson annotations, and generate the documentation that way.

我更愿意使用已经存在的解决方案来编写一次性的东西.我发现这个 Swagger 模块声称它可以解析 Jackson 配置(https://github.com/FasterXML/jackson-module-swagger),但我对 Swagger 的了解还不够,无法理解模块是什么以及我是否可以使用它从现有代码生成 Swagger.

I would prefer to use a solution that already exists to writing a one-off thing. I found this Swagger module that claims it can parse Jackson configurations (https://github.com/FasterXML/jackson-module-swagger) but I don't know enough about Swagger to understand what modules are and whether I can use it to generate Swagger from existing code.

推荐答案

你可能想看看这个项目:https://github.com/sdaschner/jaxrs-analyzer

You might want to have a look at this project: https://github.com/sdaschner/jaxrs-analyzer

它可以为 JAX-RS 自动生成 Swagger 文档.据我所知,没有考虑杰克逊特定的注释.

It can generate Swagger documentation automatically for JAX-RS. As far as I know Jackson specific annotations are not taken into consideration.

 
精彩推荐
图片推荐