Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

node.js - How to organise/build a Swagger UI interface for a directory which contains many Swagger definition .json/.yml files

I am trying to document, via Swagger UI, for internal company consumption, existing API services which are developed in a vendor product (WSO2 ESB). The vendor product does not support swagger. I plan to programmatically inspect/process the source code for my API services (written in the vendor product) and generate a directory/folder/library of swagger definition files in .json or .yml format. That is fine, I can do that.

Each of these api defintion files will render nicely in swagger UI, I am looking at using https://www.npmjs.com/package/swagger-ui.

My issue is I will end up with around 100 of these API definition files, I would like to provide some overarching interface/page which lists all of the API's and then takes the user to Swagger UI with the particular API definition loaded when the user clicks on one of the links. This is equivalent to opening my local swagger-ui and manually typing/copying in the path to the relevant API definition. This works fine if I do it manually, I just don't want the user to have to do this manually. How would they know what API definition url's exist and why make them manually type/copy them in.

I can't see how to pass a "apiDefintionToLoad" parameter into Swagger-ui, I guess I will either find one or change the source to support that. Does this exist?

Is there a better solution, either to develop myself or using an existing package or solution? I prefer node based solutions, java is also ok.

Am I going at this wrong?

Thanks, Matt.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Swagger UI 3.0.19 natively supports multiple specs via the urls parameter. When urls is used, the top bar displays a drop-down list of specs instead of an input box.

Usage

Edit distindex.html and change

url: "http://petstore.swagger.io/v2/swagger.json",

to

urls: [
   {name: "petstore",  url: "http://petstore.swagger.io/v2/swagger.json"},
   {name: "instagram", url: "https://api.apis.guru/v2/specs/instagram.com/1.0.0/swagger.yaml"}
],
"urls.primaryName": "petstore",  // default spec


Now your Swagger UI top bar looks like this:

Swagger UI top bar with spec selector


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...