How to use @loopback/openapi-spec-builder - 10 common examples

To help you get started, we’ve selected a few @loopback/openapi-spec-builder 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 / openapi-v3 / src / __tests__ / unit / decorators / param / param.decorator.unit.ts View on Github external
it('infers array parameter type with `any`', () => {
      class MyController {
        @get('/greet')
        greet(
          @param.array('names', 'query', {type: 'string'})
          names: // eslint-disable-next-line @typescript-eslint/no-explicit-any
          any,
        ) {}
      }

      const actualSpec = getControllerSpec(MyController);

      const expectedSpec = anOperationSpec()
        .withOperationName('greet')
        .withControllerName('MyController')
        .withResponse(200, {description: 'Return value of MyController.greet'})
        .withParameter({
          name: 'names',
          schema: {
            type: 'array',
            items: {
              type: 'string',
            },
          },
          in: 'query',
        })
        .build();

      expect(actualSpec.paths['/greet']['get']).to.eql(expectedSpec);
github strongloop / loopback-next / benchmark / src / rest-routing / routing-table.ts View on Github external
function givenNumberOfRoutes(base: string, num: number) {
  const spec = anOpenApiSpec();
  let i = 0;
  while (i < num) {
    // Add 1/4 paths with vars
    if (i % 4 === 0) {
      spec.withOperationReturningString(
        'get',
        `${base}/group${i}/{version}`,
        `greet${i}`,
      );
    } else {
      spec.withOperationReturningString(
        'get',
        `${base}/group${i}/version_${i}`,
        `greet${i}`,
      );
    }
github strongloop / loopback-next / packages / openapi-v3 / src / __tests__ / unit / decorators / operation.decorator.unit.ts View on Github external
it('returns spec defined via @api()', () => {
    const expectedSpec = anOpenApiSpec()
      .withOperationReturningString('get', '/greet', 'greet')
      .build();

    @api(expectedSpec)
    class MyController {
      greet() {
        return 'Hello world!';
      }
    }

    const actualSpec = getControllerSpec(MyController);
    expect(actualSpec).to.eql(expectedSpec);
  });
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / rest.server / rest.server.open-api-spec.unit.ts View on Github external
it('preserves routes specified in app.api()', () => {
    function status() {}
    server.api(
      anOpenApiSpec()
        .withOperation('get', '/status', {
          'x-operation': status,
          responses: {},
        })
        .build(),
    );

    function greet() {}
    server.route('get', '/greet', {responses: {}}, greet);

    const spec = server.getApiSpec();
    expect(spec.paths).to.eql({
      '/greet': {
        get: {
          responses: {},
        },
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / router / routing-table.unit.ts View on Github external
it('finds simple "GET /hello/world" endpoint', () => {
    const spec = anOpenApiSpec()
      .withOperationReturningString('get', '/hello/{msg}', 'greet')
      .withOperationReturningString('get', '/hello/world', 'greetWorld')
      .build();

    class TestController {}

    const table = givenRoutingTable();
    table.registerController(spec, TestController);

    const request = givenRequest({
      method: 'get',
      url: '/hello/world',
    });

    const route = table.find(request);
    expect(route)
github strongloop / loopback-next / packages / rest / src / __tests__ / integration / rest.application.integration.ts View on Github external
it('honors basePath for routes', async () => {
    givenApplication();
    restApp.basePath('/api');
    restApp.route('get', '/status', anOperationSpec().build(), () => ({
      running: true,
    }));

    await restApp.start();
    client = createRestAppClient(restApp);
    await client.get('/api/status').expect(200, {running: true});
  });
github strongloop / loopback-next / packages / openapi-v3 / src / __tests__ / unit / decorators / operation.decorator.unit.ts View on Github external
it('allows children to override parent REST parameters', () => {
    const operationSpec = anOperationSpec()
      .withStringResponse()
      .build();

    class Parent {
      @get('/greet', operationSpec)
      greet(@param.query.string('msg') msg: string) {
        return `Parent: ${msg}`;
      }
    }

    class Child extends Parent {
      greet(@param.query.string('message') msg: string) {
        return `Child: ${msg}`;
      }
    }
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / rest.server / rest.server.unit.ts View on Github external
it('returns a function for invoking a route handler', async () => {
      function greet() {
        return 'Hello world';
      }

      const route = new Route(
        'get',
        '/greet',
        anOperationSpec().build(),
        greet,
      );

      const ctx = await givenRequestContext();
      const invokeMethod = await ctx.get(
        RestBindings.SequenceActions.INVOKE_METHOD,
      );

      const result = await invokeMethod(route, []);
      expect(result).to.equal('Hello world');
    });
  });
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / rest.server / rest.server.open-api-spec.unit.ts View on Github external
it('emits all media types for request body', () => {
    const expectedOpSpec = anOperationSpec()
      .withRequestBody({
        description: 'Any object value.',
        required: true,
        content: {
          'application/json': {
            schema: {type: 'object'},
          },
          'application/x-www-form-urlencoded': {
            schema: {type: 'object'},
          },
        },
      })
      .withResponse(200, {
        content: {
          'application/json': {
            schema: {
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / router / handler-route.unit.ts View on Github external
it('implements toString', () => {
      const spec = anOperationSpec().build();
      const route = new Route('get', '/greet', spec, () => {});
      expect(route.toString()).to.equal('Route - get /greet');
      expect(new RouteSource(route).toString()).to.equal('get /greet');
    });
  });

@loopback/openapi-spec-builder

Make it easy to create OpenAPI (Swagger) specification documents in your tests using the builder pattern.

MIT
Latest version published 2 months ago

Package Health Score

84 / 100
Full package analysis