How to use openapi-framework - 2 common examples

To help you get started, we’ve selected a few openapi-framework 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 kogosoftwarellc / open-api / packages / koa-openapi / index.ts View on Github external
const securityFilter =
    args.securityFilter ||
    function defaultSecurityFilter(ctx, next) {
      ctx.status = 200;
      ctx.body = ctx.state.apiDoc;
    };

  const frameworkArgs: OpenAPIFrameworkConstructorArgs = {
    apiDoc: args.apiDoc,
    featureType: 'middleware',
    name: loggingPrefix,
    paths: args.paths,
    ...(args as OpenAPIFrameworkArgs)
  };

  const framework = new OpenAPIFramework(frameworkArgs);

  framework.initialize({
    visitApi(apiCtx: OpenAPIFrameworkAPIContext) {
      const basePaths = apiCtx.basePaths.map(toKoaBasePath);
      for (const basePath of basePaths) {
        if (exposeApiDocs) {
          // Swagger UI support
          router.get(basePath + docsPath, (ctx: Context, next) => {
            ctx.state.apiDoc = apiCtx.getApiDoc();
            if (ctx.state.apiDoc.swagger) {
              ctx.state.apiDoc.host = ctx.headers.host;
              ctx.state.apiDoc.basePath =
                basePath.length === 0 ? '/' : basePath;
            }
            securityFilter(ctx, next);
          });
github kogosoftwarellc / open-api / packages / express-openapi / index.ts View on Github external
const promiseMode = !!args.promiseMode;
  const securityFilter = args.securityFilter
    ? args.promiseMode
      ? toPromiseCompatibleMiddleware(args.securityFilter)
      : args.securityFilter
    : function defaultSecurityFilter(req, res, next) {
        res.status(200).json(req.apiDoc);
      };

  const frameworkArgs: OpenAPIFrameworkConstructorArgs = {
    featureType: 'middleware',
    name: loggingPrefix,
    ...(args as OpenAPIFrameworkArgs)
  };

  const framework = new OpenAPIFramework(frameworkArgs);

  framework.initialize({
    visitApi: ctx => {
      if (exposeApiDocs || errorMiddleware) {
        const basePaths = [];
        basePaths.push(...ctx.basePaths.map(toExpressBasePath));

        for (const basePath of basePaths) {
          // Swagger UI support
          if (exposeApiDocs) {
            app.get(basePath + docsPath, (req, res, next) => {
              // @ts-ignore
              req.apiDoc = ctx.getApiDoc();
              // @ts-ignore
              if (req.apiDoc.swagger) {
                // @ts-ignore

openapi-framework

An OpenAPI framework for any web framework

MIT
Latest version published 1 year ago

Package Health Score

65 / 100
Full package analysis

Popular openapi-framework functions