@ts-awesome/openapi
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@ts-awesome/openapi

OpenApi provider and UI. Schema is collected from decorators.

Library is an extension for @ts-awesome/rest

Common params declarations

export const SORT: IOpenApiParameterArgs = {
  description: `Sort pattern`,
  schema: {
    type: OpenApiDataType.string,
  }
};

export const OFFSET: IOpenApiParameterArgs = {
  description: `Offset`,
  schema: {
    type: OpenApiDataType.integer,
    minimum: 0,
  }
};

export const LIMIT: IOpenApiParameterArgs = {
  description: `Limit`,
  schema: {
    type: OpenApiDataType.integer,
    minimum: 1,
    maximum: 100,
  }
};

export const COUNT_ONLY: IOpenApiParameterArgs = {
  description: `Get total count`,
  schema: {
    type: OpenApiDataType.boolean,
  },
};

export const UID: IOpenApiParameterArgs = {
  description: 'UUID',
  required: true,
  schema: {
    type: OpenApiDataType.string,
    format: 'uuid',
  }
};

Sample endpoint decorator

export class GetDeviceRoute {

  @OpenApiOperationGet({
    path: '/api/v1/device/{uid}',
    description: `Get device`,
    summary: `Get device`,
    request: {
      path: {
        uid: UID,
      },
      query: {
        sort: SORT,
        offset: OFFSET,
        limit: LIMIT,
        count: COUNT_ONLY,
      }
    },
    responses: {
      200: {content: DeviceResponseModel}
    }
  })
  public handle() {}
}

Declare endpoints group

export * from './get-device.route';

OpenApiPath({
  path: '/api/v1/device',
  tag: 'Device',
  security: [{ BearerAuth: [] }]
});

Sample use with express

app.use(openApi({
    def: {
      info: {
        title: 'My API',
        version: '1.0.0'
      },
      components: {
        securitySchemes: {
          BearerAuth: {
            type: 'http',
            scheme: OpenApiHttpSecurityScheme.bearer,
            bearerFormat: 'JWT',
          }
        }
      },
    }
}));

License

May be freely distributed under the MIT license.

Copyright (c) 2022 Volodymyr Iatsyshyn and other contributors

Readme

Keywords

none

Package Sidebar

Install

npm i @ts-awesome/openapi

Weekly Downloads

64

Version

1.0.1

License

MIT

Unpacked Size

69.6 kB

Total Files

71

Last publish

Collaborators

  • ts-awesome-bot
  • viatsyshyn