All files / api/swagger swaggerBuilder.ts

100% Statements 65/65
100% Branches 5/5
100% Functions 5/5
100% Lines 65/65

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 661x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 5x 5x 5x 5x 5x 8x 8x 1x 1x 1x 1x 1x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 8x  
import { OpenAPIV3_1 } from 'openapi-types';
 
import { site } from '@constants/site';
import { getVersionNumFromPackageJson } from '@helpers/fileHelper';
import { getConfig } from '@services/internal/configService';
 
export class SwaggerBuilder {
  private paths = {};
  private components = {};
 
  addPath(path: OpenAPIV3_1.PathItemObject) {
    this.paths = {
      ...this.paths,
      ...path,
    };
  }
 
  addComponent(component: Record<string, OpenAPIV3_1.SchemaObject>) {
    this.components = {
      ...this.components,
      ...component,
    };
  }
 
  getCustomCss = (): string => `
    .swagger-ui .topbar .download-url-wrapper {
      display: none;
    }
 
    tr.response:not([data-code^='2']) .model-example {
      display: none;
    }
 
    table td:nth-child(3) {
      display: none;
    }
  `;
 
  toSpec(): OpenAPIV3_1.Document {
    const spec: OpenAPIV3_1.Document = {
      openapi: '3.1.0',
      info: {
        title: 'NMSUD Form API',
        summary: 'An "easy to use" way of interacting with the API powering the NMSUD Form UI',
        termsOfService: getConfig().getNmsUdFormDocsUrl() + '/misc/terms_and_conditions.html',
        contact: {
          name: site.nmsud.name,
          url: site.nmsud.website,
          email: site.nmsud.email,
        },
        license: {
          name: 'GNU General Public License v3.0',
          identifier: 'GPL-3.0',
          url: 'https://github.com/NMSUD/Form/blob/main/LICENCE.md',
        },
        version: getVersionNumFromPackageJson(),
      },
      paths: this.paths,
      components: {
        schemas: this.components,
      },
    };
    return spec;
  }
}