如何为包含许多Swagger定义.json/.yml文件的目录组织/构建Swagger UI界面 [英] How to organise/build a Swagger UI interface for a directory which contains many Swagger definition .json/.yml files

查看:602
本文介绍了如何为包含许多Swagger定义.json/.yml文件的目录组织/构建Swagger UI界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Swagger UI为公司内部使用记录在供应商产品(WSO2 ESB)中开发的现有API服务.供应商产品不支持摇摇欲坠.我计划以编程方式检查/处理我的API服务的源代码(用卖方产品编写),并生成.json或.yml格式的swagger定义文件的目录/文件夹/库.很好,我可以做到.

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.

每个这些api定义文件都可以在swagger UI中很好地呈现,我正在使用 https: //www.npmjs.com/package/swagger-ui .

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

我的问题是,我最终将获得大约100个这些API定义文件,我想提供一些概述界面/页面,其中列出了所有API,然后将用户带到Swagger UI,并在加载特定API定义时用户单击链接之一.这等效于打开我的本地swagger-ui并在相关API定义的路径中手动键入/复制.如果我手动执行此操作,则效果很好,只是我不希望用户手动执行此操作.他们将如何知道存在哪些API定义网址以及为什么要手动键入/复制它们.

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.

我看不到如何将"apiDefintionToLoad"参数传递给Swagger-ui,我想我要么找到一个参数,要么更改源代码以支持该参数.是否存在?

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?

是否有更好的解决方案,无论是自己发展还是使用现有的软件包或解决方案?我更喜欢基于节点的解决方案,java也可以.

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.

我要错了吗?

谢谢, 马特.

推荐答案

使用基本的Swagger-ui工具可以非常轻松地完成您要查找的内容.

what you're looking for can be done very easily with the basic Swagger-ui tool.

基本上,您所拥有的是许多摇摇欲坠的定义的列表.我猜您想让用户单击按钮或链接,或者从下拉列表中选择定义以选择要查看的API.完成后,您可以执行以下操作:

Essentially what you have is a list of many swagger definitions. I'm guessing that you want to let the user click a button or a link, or choose a definition from a drop-down to select the API to view. Once that's done, you can do the following:

  • 让用户选择要显示的API定义.您可以通过在index.html中添加HTML元素并在选择后触发一些javascript来轻松实现
  • 单个swagger-ui容器可以重新加载和重用.从第一步获取到swagger定义的URL,并将其提供给swagger-ui对象,通常是这样完成的:

  • Let the user choose an API definition to show. You can get this easily from adding a HTML element to your index.html and trigging some javascript after selecting
  • A single swagger-ui container can be reloaded and reused. Get the URL to the swagger definition from the first step and supply it to the swagger-ui object, which is typically done like this:

window.swaggerUi.updateSwaggerUi({url: 'http://your.spec.com/swagger.yaml'})

现在,容器将重新加载您指定的规范.

Now the container will reload with the spec you've specified.

这篇关于如何为包含许多Swagger定义.json/.yml文件的目录组织/构建Swagger UI界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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