[英]How to display Swagger JSON file in my MEAN stack project using swagger-ui module?
I'm new to NodeJS and AngularJS so I might be approaching this completely wrong but worth asking... 我是NodeJS和AngularJS的新手,所以我可能会遇到完全错误的问题,但值得一提...
I'm trying to use the swagger-ui Node module to display my API's documentation in a Swagger-ish style with interactivity. 我正在尝试使用swagger-ui Node模块以具有交互性的Swagger风格显示我的API文档。
I want to do this within my NodeJS app by passing in my own Swagger JSON file (hosted in public/assets/my-swagger.json
). 我想通过传入我自己的Swagger JSON文件(位于public/assets/my-swagger.json
)在public/assets/my-swagger.json
应用程序中执行此操作。
I'm assuming I can do something like this: 我假设我可以做这样的事情:
angular.module('SwaggerCtrl', []).controller('SwaggerController', function($scope) {
$scope.swagger = new function() {
var swaggerUi = new SwaggerUi({
url: '../../assets/my-swagger.json',
dom_id: "swagger-ui-container"
});
swaggerUi.load();
};
});
Which is taken from https://www.npmjs.com/package/swagger-ui#swaggerui . 取自https://www.npmjs.com/package/swagger-ui#swaggerui 。
And then in my swagger.html
I would do something like this: 然后在我的swagger.html
我将执行以下操作:
<div class="jumbotron text-center">
<h1>Swagger</h1>
<p>{{ swagger }}</p>
<div id="swagger-ui-container"></div>
</div>
However, when I go to http://localhost:8080/swagger , I get ReferenceError: SwaggerUi is not defined
error message on my console. 但是,当我转到http:// localhost:8080 / swagger时 ,出现ReferenceError: SwaggerUi is not defined
在控制台上ReferenceError: SwaggerUi is not defined
错误消息。
I'm trying to figure out how to call the swaggerUi.load()
so that it loads the my-swagger.json
file when the user goes to http://localhost:8080/swagger . 我试图弄清楚如何调用swaggerUi.load()
以便在用户转到http:// localhost:8080 / swagger时加载my-swagger.json
文件。
I also looked at https://www.npmjs.com/package/swagger-ui-middleware but it's loading the default Petstore API found in the node_modules/swagger-ui/dist
directory. 我还查看了https://www.npmjs.com/package/swagger-ui-middleware,但是它正在加载在node_modules/swagger-ui/dist
目录中找到的默认Petstore API。
I'm new to this too and have used those two modules: swagger-jsdoc (it generates the swagger.json from comments in your node.js file and swagger-ui-express to display the information. 我也是新手,并且使用了这两个模块:swagger-jsdoc(它从node.js文件中的注释生成swagger.json和swagger-ui-express以显示信息。
Look at the doc for the later, you might find the answer to your question. 稍后查看文档,您可能会找到问题的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.