代码之家  ›  专栏  ›  技术社区  ›  TechChain

Swageer js doc不在更改时即时更新api文档?

  •  1
  • TechChain  · 技术社区  · 5 年前

    我在用 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编写了文档。我从浏览器中点击了url

    localhost:3000/v1/docs
    

    这显示了在swagger ui中记录的api。但是当我在任何yaml文件中进行更新并刷新页面时,我都看不到更新的更改。我必须阻止 nodemon 处理并重新启动我不想做的处理。让我知道我该怎么做?

    1 回复  |  直到 5 年前
        1
  •  4
  •   Sahil    5 年前

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

    nodemon-e山药

    有关详细信息,请参阅官方文档: https://www.npmjs.com/package/nodemon