How to use the @loopback/openapi-spec-builder.anOperationSpec function in @loopback/openapi-spec-builder

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 / 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');
    });
  });
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / router / controller-route.unit.ts View on Github external
it('rejects routes with no methodName', () => {
    const spec = anOperationSpec().build();

    expect(
      () => new ControllerRoute('get', '/greet', spec, MyController),
    ).to.throw(/methodName must be provided.*"get \/greet".*MyController/);
  });
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / router / trie-router.unit.ts View on Github external
function addRoute(
  routes: RouteEntry[],
  op: string,
  verb: string,
  path: string,
) {
  routes.push({
    verb,
    path,
    spec: anOperationSpec()
      .withOperationName(op)
      .build(),
    updateBindings: () => {},
    invokeHandler: async () => {},
    describe: () => op,
  });
}

@loopback/openapi-spec-builder

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

MIT
Latest version published 11 days ago

Package Health Score

87 / 100
Full package analysis