How to use swagger-ui-express - 10 common examples

To help you get started, we’ve selected a few swagger-ui-express examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github devin-huang / RESTful_API / swagger / swaggerDoc.js View on Github external
module.exports = (app) => {
  // 开放 swagger 相关接口,
  app.get('/swagger.json', function(req, res) {
    res.setHeader('Content-Type', 'application/json')
    res.send(swaggerSpec)
  }),
  app.use(swaggerConfig.routerPath, swaggerUi.serve, swaggerUi.setup(swaggerSpec))
  
}
github SayakMukhopadhyay / elitebgs / server.js View on Github external
res.setHeader('Content-Type', 'application/json');
    res.send(swagger.EBGSAPIv2);
});

app.use('/api/ebgs/v3/api-docs.json', (req, res, next) => {
    res.setHeader('Content-Type', 'application/json');
    res.send(swagger.EBGSAPIv3);
});

app.use('/api/ebgs/v4/api-docs.json', (req, res, next) => {
    res.setHeader('Content-Type', 'application/json');
    res.send(swagger.EBGSAPIv4);
});

app.use('/api/ebgs/v1/docs', swaggerUi.serve, swaggerUi.setup(swagger.EBGSAPIv1));
app.use('/api/ebgs/v2/docs', swaggerUi.serve, swaggerUi.setup(swagger.EBGSAPIv2));
app.use('/api/ebgs/v3/docs', swaggerUi.serve, swaggerUi.setup(swagger.EBGSAPIv3));
app.use('/api/ebgs/v4/docs', swaggerUi.serve, swaggerUi.setup(swagger.EBGSAPIv4));

app.use('/api/ebgs/v4/factions', ebgsFactionsV4);
app.use('/api/ebgs/v4/systems', ebgsSystemsV4);
app.use('/api/ebgs/v4/stations', ebgsStationsV4);
app.use('/api/ebgs/v4/ticks', tickTimesV4);

app.use('/auth/check', authCheck);
app.use('/auth/discord', authDiscord);
app.use('/auth/logout', authLogout);
app.use('/auth/user', authUser);
app.use('/frontend', frontEnd);
app.use('/chartgenerator', chartGenerator);

// Pass all 404 errors called by browser to angular
github bkimminich / juice-shop / server.js View on Github external
/* /ftp directory browsing and file download */
app.use('/ftp', serveIndex('ftp', { icons: true }))
app.use('/ftp/:file', fileServer())

/* /encryptionkeys directory browsing */
app.use('/encryptionkeys', serveIndex('encryptionkeys', { icons: true, view: 'details' }))
app.use('/encryptionkeys/:file', keyServer())

/* /logs directory browsing */
app.use('/support/logs', serveIndex('logs', { icons: true, view: 'details' }))
app.use('/support/logs', verify.accessControlChallenges())
app.use('/support/logs/:file', logFileServer())

/* Swagger documentation for B2B v2 endpoints */
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))

app.use(express.static(path.join(__dirname, '/frontend/dist/frontend')))
app.use(cookieParser('kekse'))

/* Configure and enable backend-side i18n */
i18n.configure({
  locales: locales.map(locale => locale.key),
  directory: path.join(__dirname, '/i18n'),
  cookie: 'language',
  defaultLocale: 'en',
  autoReload: true
})
app.use(i18n.init)

app.use(bodyParser.urlencoded({ extended: true }))
/* File Upload */
github godaddy / bucket-service / lib / routes / swagger.js View on Github external
/* istanbul ignore file */
const Router = require('express').Router;
const getSwaggerSpec = require('../services/swagger');
const swaggerUi = require('swagger-ui-express');

const routes = new Router();

routes.get('/api-docs.json', (req, res) => {
  res.setHeader('Content-Type', 'application/json');
  res.send(getSwaggerSpec(req));
});

routes.use('/', swaggerUi.serve, (req, res, next) => {
  const swaggerUiHandler = swaggerUi.setup(getSwaggerSpec(req));
  swaggerUiHandler(req, res, next);
});

module.exports = routes;
github CodeChain-io / codechain-indexer / src / server.ts View on Github external
// Enable reverse proxy support in Express. This causes the
    // the "X-Forwarded-Proto" header field to be trusted so its
    // value can be used to determine the protocol. See
    // http://expressjs.com/api#app-settings for more details.
    app.enable("trust proxy");
    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(
        bodyParser.json({
            type: () => true // Treat all other content types as application/json
        })
    );

    if (process.env.NODE_ENV === "dev") {
        app.use(
            "/api-docs",
            swaggerUi.serve,
            swaggerUi.setup(swaggerSpec, { explorer: true })
        );
    }

    app.use("/api", createApiRouter(context, true));
    app.use(handleErrors);

    return app;
}
github ERS-HCL / nxplorerjs-microservice-starter / server / common / swagger / index.ts View on Github external
middleware.validateRequest());

    // Error handler to display the validation error as HTML
    app.use(function (err, req, res, next) {
      res.status(err.status);
      res.send(
        '<h1>' + err.status + ' Error</h1>' +
        '<pre>' + err.message + '</pre>'
      );
    });

    routes(app);
  });

  const swaggerDocument = YAML.load('./server/common/swagger/Api.yaml');
  app.use('/swagger', swaggerUi.serve, swaggerUi.setup(swaggerDocument));

}
github l3tnun / EPGStation / src / server / Service / Server.ts View on Github external
// log
        this.app.use(log4js.connectLogger(this.log.access, { level: 'info' }));

        // read pkg
        const pkg = require(path.join('..', '..', '..', 'package.json'));

        // read api.yml
        let api = yaml.safeLoad(fs.readFileSync(path.join(__dirname, '..', '..', '..', 'api.yml'), 'utf-8'));
        api.info = {
            version: pkg.version,
            title: pkg.name,
        }

        // swagger ui
        const swaggerUi = require('swagger-ui-express');
        this.app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(api));
        this.app.get('/api/debug', (_req, res) => res.redirect('/api-docs/?url=/api/docs'));

        // init express-openapi
        openapi.initialize({
            app: this.app,
            apiDoc: api,
            paths: path.join(__dirname, 'api'),
            consumesMiddleware: {
                'application/json': bodyParser.json(),
                'text/text': bodyParser.text()
            },
            errorMiddleware: (err, _req, res, _next) => {
                res.status(400);
                res.json(err);
            },
            errorTransformer: (openapi, _jsonschema) => {
github circa10a / express-jwt / routes / routes.js View on Github external
const jwt = require('jsonwebtoken');
const basicAuth = require('express-basic-auth');

const swaggerUi = require('swagger-ui-express');
const swaggerJSDoc = require('swagger-jsdoc');

const invalidTokenHandler = require('../middleware/invalidTokenHandler');
const { privateKey, publicKey } = require('../lib/keys');
const { jwtConfig, basicAuthConfig, swaggerConfig } = require('../config/config');

const swaggerSpec = swaggerJSDoc(swaggerConfig);

const router = express.Router();

// Ensure user gets to api docs
router.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));

router.get('/', (req, res) => {
  res.redirect('/api-docs');
});

router.get('/healthCheck', (req, res) => {
  res.sendStatus(200);
});

/**
   * @swagger
   * /login:
   *   get:
   *     summary: Login to the application via basic auth(use admin:admin)
   *     tags: [Login (Get JWT)]
   *     security:
github eropple / nestjs-openapi3 / src / openapi.module.ts View on Github external
private static serveSwagger(
    document: O3TS.OpenAPIObject,
    apiDocsPath: string,
    logger: BunyanLike,
    app: INestApplication,
    httpAdapter: HttpServer,
  ) {
    try {
      // tslint:disable-next-line: no-require-imports
      const swaggerUi = require('swagger-ui-express');

      const html = swaggerUi.generateHTML(document, {});

      app.use(apiDocsPath, swaggerUi.serveFiles(document, {}));
      httpAdapter.get(apiDocsPath, (req, res) =&gt; res.contentType('html').send(html));

    } catch (err) {
      logger.warn({ err }, 'Error when loading `swagger-ui-express`. Make sure you have it in your package.json.');
    }
  }
github egodigital / swagger-jsdoc-express / src / index.ts View on Github external
favIcon = null;
    }

    let url = toStringSafe(opts.url);
    if (isEmptyString(url)) {
        url = null;
    }

    let title = toStringSafe(opts.title);
    if (isEmptyString(title)) {
        title = null;
    }

    const ROUTER = express.Router();

    ROUTER.use('/', swaggerUi.serveFiles(SWAGGER_DOC));
    ROUTER.get('/', swaggerUi.setup(
        SWAGGER_DOC,
        null,  // opts
        null,  // options
        css,  // customCss
        favIcon,  // customfavIcon
        url,  // swaggerUrl
        title,  // customeSiteTitle
    ));

    // download link (JSON)
    ROUTER.get(`/json`, function (req, res) {
        return res.status(200)
            .header('content-type', 'application/json; charset=utf-8')
            .header('content-disposition', `attachment; filename=api.json`)
            .send(

swagger-ui-express

Swagger UI Express

MIT
Latest version published 6 months ago

Package Health Score

77 / 100
Full package analysis