从现有的 REST api 生成 Swagger 文档 [英] Generating Swagger documentation from existing REST api

查看:42
本文介绍了从现有的 REST api 生成 Swagger 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个现有的带有 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.

这篇关于从现有的 REST api 生成 Swagger 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆