node.js - Swageer js doc 不会即时更新 api 文档的更改?
问题描述
我正在使用swagger-jsdoc
我在 app.js 中设置了如下所示的 swagger js 文档
//include swagger js doc
var swaggerJSDoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const pathToSwaggerUi = require('swagger-ui-dist').absolutePath()
const swaggerDefinition = {
swagger: '2.0',
info: {
// API informations (required)
title: 'API', // Title (required)
version: '1.0.0', // Version (required)
description: 'Used for api documentation', // Description (optional)
},
host: `localhost:3000`, // Host (optional)
basePath: '/app/v1', // Base path (optional)
};
// Options for the swagger docs
const options = {
// Import swaggerDefinitions
swaggerDefinition,
// Path to the API docs
// Note that this path is relative to the current directory from which the Node.js is ran, not the application itself.
apis: ['./app/v1/docs/*.yaml']
};
// Initialize swagger-jsdoc -> returns validated swagger spec in json format
const swaggerSpec = swaggerJSDoc(options);
app.use('/v1/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
我有某些 yaml 文件,我为记录 api 编写了这些文件。我从浏览器点击网址
localhost:3000/v1/docs
这向我展示了 swagger ui 中记录的 api。但是当我在任何 yaml 文件中进行更新并刷新页面时,我看不到更新的更改。我必须停止该nodemon
过程并再次重新启动我不想这样做的过程。所以让我知道我该怎么做?
解决方案
默认情况下,nodemon 会查找扩展名为 .js、.mjs、.coffee、.litcoffee 和 .json 的文件。
要添加其他扩展,请使用以下命令:nodemon -e yaml
更多详情请参考官方文档:https ://www.npmjs.com/package/nodemon
推荐阅读
- python - 如何在列表中重复一个整数 n,n 次(python)?
- python-3.x - Django 3.x Python 3.x - 如何解决内部服务器错误?
- javascript - 使用材料 ui 在反应中更新主题状态
- xamarin.forms - 如何在 Xamarin Forms 中打印图像?
- c - 为什么C标准库没有提供知道分配内存大小的功能?
- ios - Swift:使用枚举来表示扑克牌的等级
- python - 如何使用 selenium python 读取动态文本
- couchdb - 如果字段包含子字符串,如何选择文档
- networking - 使用 docker compose 在一个网络中使用动态 IP,在其他网络中使用静态 IP
- css - 悬停时过渡三角形的一些问题,当将鼠标移出时颜色恢复如此之快