How to use the @loopback/rest.rebaseOpenApiSpec function in @loopback/rest

To help you get started, we’ve selected a few @loopback/rest 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 strongloop / loopback-next / examples / lb3app / src / application.ts View on Github external
// Wait until the legacy LB3 app boots
      await pEvent(legacyApp, 'booted');
    }

    debug('MOUNT LB3 APP');
    const swaggerSpec = generateSwaggerSpec(legacyApp);
    const result = await swagger2openapi.convertObj(swaggerSpec, {
      // swagger2openapi options
    });
    const openApiSpec: OpenAPIObject = result.openapi;

    // Option A: mount the entire LB3 app, including any request-preprocessing
    // middleware like CORS, Helmet, loopback#token, etc.

    // 1. Rebase the spec, e.g. from `GET /Products` to `GET /api/Products`.
    const specInRoot = rebaseOpenApiSpec(openApiSpec, swaggerSpec.basePath);
    if (debug.enabled)
      debug(
        'API of LB3 app',
        Object.keys(specInRoot.paths)
          .map(p =>
            Object.keys(specInRoot.paths[p])
              .map(v => `\n\t${v.toUpperCase()} ${p}`)
              .join(''),
          )
          .join(''),
      );

    // 2. Mount the full Express app
    this.mountExpressRouter('/', specInRoot, legacyApp);

    /* Options B: mount LB3 REST handler only.
github strongloop / loopback-next / packages / booter-lb3app / src / lb3app.booter.ts View on Github external
private mountFullApp(lb3App: Lb3Application, spec: OpenApiSpec) {
    const restApiRoot = lb3App.get('restApiRoot') || '/';
    debug('Mounting the entire LB3 app at %s', restApiRoot);
    const specInRoot = rebaseOpenApiSpec(spec, restApiRoot);
    this.app.mountExpressRouter('/', lb3App, specInRoot);
  }