我如何在醒目的UI中将某些端点私有和将某些端点公开

时间:2019-09-02 09:12:39

标签: node.js swagger-ui swagger-jsdocs

我在swagger UI中有一些端点必须是私有的,而某些端点是公共的,可以通过键入“ domain / private / api-docs”(私有)和“ domain / api-docs”(公共)来访问。在升级swagger UI之前,此方法运行良好。

  const swaggerPublicOptions  =
                        { swaggerDefinition:
                            { swagger: '2.0'
                            , basePath: `/v1`   
                            }
                        , apis:
                            [
                             // routes here 
                            ]
                        };

        const swaggerSpec = swaggerJSDoc(swaggerPublicOptions);
        this.app.get('/swagger.json', function(req, res) {
            res.setHeader('Content-Type', 'application/json');
            res.send(swaggerSpec);
        });

const swaggerOptions =
                        { swaggerDefinition:
                            { swagger: '2.0',
                             basePath: `/v1`   
                            }
                        , apis:
                            [ 
                                // routes here 
                            ]
                        };

        const swaggerPrivateSpec = swaggerJSDoc(swaggerOptions);
        this.app.get('/swagger.private.json', function(req, res) {
            res.setHeader('Content-Type', 'application/json');
            res.send(swaggerPrivateSpec);
        });

    this.app.use('/private/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerPrivateSpec, true, customOptions));
    this.app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec,options));

0 个答案:

没有答案