gpt4 book ai didi

node.js - Swagger jsdoc 不会在更改时立即更新 api 文档吗?

转载 作者:太空宇宙 更新时间:2023-11-03 22:49:11 26 4
gpt4 key购买 nike

我正在使用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));

我有一些为 api 文档编写的 yaml 文件。我从浏览器中点击了 url

localhost:3000/v1/docs

这向我展示了 swagger ui 中记录的 api。但是当我在任何 yaml 文件中进行更新并刷新页面时,我看不到更新的更改。我必须停止 nodemon 进程并再次重新启动该进程,但我不想这样做。那么让我知道我该怎么做?

最佳答案

默认情况下,nodemon 会查找扩展名为 .js、.mjs、.coffee、.litcoffee 和 .json 的文件。

要添加其他扩展,请使用以下命令: Nodemon -e yaml

更多详情请引用官方文档:https://www.npmjs.com/package/nodemon

关于node.js - Swagger jsdoc 不会在更改时立即更新 api 文档吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55932251/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com