How to use the @loopback/openapi-v3.api function in @loopback/openapi-v3

To help you get started, we’ve selected a few @loopback/openapi-v3 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 / packages / rest / src / __tests__ / acceptance / sequence / sequence.acceptance.ts View on Github external
const apispec = anOpenApiSpec()
      .withOperation('get', '/name', {
        'x-operation-name': 'getName',
        responses: {
          '200': {
            schema: {
              type: 'string',
            },
            description: '',
          },
        },
      })
      .build();

    @api(apispec)
    class InfoController {
      constructor(@inject('application.name') public appName: string) {}

      async getName(): Promise {
        return this.appName;
      }
    }
    givenControllerInServer(InfoController);
  }
  /* ===== HELPERS ===== */
github strongloop / loopback-next / packages / authentication / src / __tests__ / acceptance / basic-auth.acceptance.ts View on Github external
function givenControllerInApp() {
    const apispec = anOpenApiSpec()
      .withOperation('get', '/whoAmI', {
        'x-operation-name': 'whoAmI',
        responses: {
          '200': {
            description: '',
            schema: {
              type: 'string',
            },
          },
        },
      })
      .build();

    @api(apispec)
    class MyController {
      constructor(
        @inject(AuthenticationBindings.CURRENT_USER) private user: UserProfile,
      ) {}

      @authenticate('BasicStrategy')
      async whoAmI(): Promise {
        return this.user.id;
      }
    }
    app.controller(MyController);
  }
github strongloop / loopback-next / labs / authentication-passport / src / __tests__ / acceptance / authentication-with-passport-strategy-adapter.acceptance.ts View on Github external
function givenControllerInApp() {
    const apispec = anOpenApiSpec()
      .withOperation('get', '/whoAmI', {
        'x-operation-name': 'whoAmI',
        responses: {
          '200': {
            description: '',
            schema: {
              type: 'string',
            },
          },
        },
      })
      .build();

    @api(apispec)
    class MyController {
      constructor(
        @inject(AuthenticationBindings.CURRENT_USER) private user: UserProfile,
      ) {}

      @authenticate(AUTH_STRATEGY_NAME)
      async whoAmI(): Promise {
        return this.user.id;
      }
    }
    app.controller(MyController);
  }
github strongloop / loopback-next / extensions / authentication-passport / src / __tests__ / acceptance / authentication-with-passport-strategy-adapter.acceptance.ts View on Github external
function givenControllerInApp() {
    const apispec = anOpenApiSpec()
      .withOperation('get', '/whoAmI', {
        'x-operation-name': 'whoAmI',
        responses: {
          '200': {
            description: '',
            schema: {
              type: 'string',
            },
          },
        },
      })
      .build();

    @api(apispec)
    class MyController {
      constructor(@inject(SecurityBindings.USER) private user: UserProfile) {}

      @authenticate(AUTH_STRATEGY_NAME)
      async whoAmI(): Promise {
        return this.user[securityId];
      }
    }
    app.controller(MyController);
  }
github strongloop / loopback-next / packages / authentication / src / __tests__ / acceptance / basic-auth-extension.acceptance.ts View on Github external
function givenControllerInApp() {
    const apispec = anOpenApiSpec()
      .withOperation('get', '/whoAmI', {
        'x-operation-name': 'whoAmI',
        responses: {
          '200': {
            description: '',
            schema: {
              type: 'string',
            },
          },
        },
      })
      .build();

    @api(apispec)
    class MyController {
      constructor() {}

      @authenticate('basic')
      async whoAmI(
        @inject(SecurityBindings.USER) userProfile: UserProfile,
      ): Promise {
        if (!userProfile) return 'userProfile is undefined';
        if (!userProfile[securityId]) return 'userProfile id is undefined';
        return userProfile[securityId];
      }
    }
    app.controller(MyController);
  }

@loopback/openapi-v3

Decorators that annotate LoopBack artifacts with OpenAPI v3 metadata and utilities that transform LoopBack metadata to OpenAPI v3 specifications

MIT
Latest version published 25 days ago

Package Health Score

95 / 100
Full package analysis