从另一个 Swagger 或 OpenAPI 文件为某些端点生成 Swagger 文件 [英] Generate a Swagger file for certain endpoints from another Swagger or OpenAPI file

查看:47
本文介绍了从另一个 Swagger 或 OpenAPI 文件为某些端点生成 Swagger 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拥有一个庞大的 Swagger/OpenAPI YAML 规范,我如何才能安全地提取某些 API 端点并专门为它们生成一个新的 .yaml?

Having one big Swagger/OpenAPI YAML specification, how can I safely extract certain API endpoints and generate a new .yaml for them exclusively?

从某个级别(例如使用一个或多个缩进定义)识别 API 端点很容易:

It's easy to identify API endpoints from a certain level (like defined with one indent or more):

paths:
  /users:
    ...
      - $ref: '#/requests/getUser'
  /repos:
    ...
requests:
  getUser:
    ...

我只是将所有部分(paths 除外)复制到一个新的规范文件中.然后我会根据缩进复制某些 paths 子部分,例如 /users: .在 Python 中,使用正则表达式.

I'd just copy all sections, except paths, into a new specs file. And then I'd copy certain paths subsections like /users: based on indents. In Python, with a regex.

但是这种直接方法对规范安全吗?

But is this direct method safe for the specs?

推荐答案

Swagger Inspector 允许您进行 API 调用,然后从中创建定义文件(让您可以根据需要选择调用的子集).请参阅 inspector.swagger.io - 它基于 UI,但可能会为您节省一些时间.

Swagger Inspector lets you make API calls and then create the definition file from them (letting you pick just a subset of calls like you want). See inspector.swagger.io - it's UI-based, but might save you some time.

这篇关于从另一个 Swagger 或 OpenAPI 文件为某些端点生成 Swagger 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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