Generate a Swagger file for certain endpoints from another Swagger or OpenAPI file

佐手、 提交于 2019-12-07 23:57:50

问题


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

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:
    ...

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?


回答1:


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.



来源:https://stackoverflow.com/questions/47590562/generate-a-swagger-file-for-certain-endpoints-from-another-swagger-or-openapi-fi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!