如何过滤生成的 Swagger JSON (yaml) [英] How to filter generated Swagger JSON (yaml)

查看:44
本文介绍了如何过滤生成的 Swagger JSON (yaml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有超过 5k 行的 swagger.json 文件描述了数百个路径和对象.我想仅使用部分端点生成 TypeScript 客户端(使用 swagger-codegen).我不希望生成的 TypeScript 应用程序包含与 swagger.json 未使用部分连接的类或接口

I have over 5k lines long swagger.json file describing hundreds of paths and objects. I want to generate a TypeScript client (using swagger-codegen) using only a part of the endpoints. I don't want the generated TypeScript application to contain classes or interfaces connected with unused part of the swagger.json

如何仅过滤掉 Swagger 文档的一部分,描述指定的路径组(例如,所有以 /api/* 开头的路径)?特别是我希望过滤后的 JSON 不包含未使用数据结构的 definitions.

How to filter out only a part of the Swagger documentation, describing the specified group of paths (e.g. all paths starting with /api/*)? Especially I want the filtered JSON to not contain definitions for unused data structures.

推荐答案

最后,我们创建了 swagger-json-filter – 一个命令行工具,允许过滤 Swagger 文档.它可以很容易地与 bash 中的其他命令一起使用:

Finally, we created swagger-json-filter – a command-line tool allowing filtering a Swagger documentation. It can be easily used along other commands in bash:

cat input.json | swagger-json-filter --include-paths="^\/api\/.*" > output.json

该工具正在执行从输出中过滤掉不需要的定义(也嵌套)所需的逻辑.

The tool is performing a logic needed to filter out undesired definitions (nested also) from the output.

这篇关于如何过滤生成的 Swagger JSON (yaml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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