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

查看:132
本文介绍了从另一个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以外的所有部分复制到一个新的specs文件中.然后根据缩进,复制某些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天全站免登陆