swagger-fix
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

swagger-fix

version downloads dependencies license Codecov

swagger-fix is a tool to fix invalid content in swagger file, make schema name and operationId valid by converting chinese to pinyin. Both OpenAPI 2.0 and 3.0 are supported.

Usage

import { fixSwagger } from 'swagger-fix';

const swagger = {
  swagger: '2.0',
  info: {
    title: 'API',
    version: '1.0.0',
  },
  paths: {
    '/api': {
      get: {
        operationId: '获取数据',
        responses: {
          200: {
            $ref: '#/definitions/数据',
          },
        },
      },
    },
  },
  definitions: {
    数据: {
      type: 'object',
      properties: {
        name: {
          type: 'string',
        },
      },
    },
  },
};

const fixedSwagger = fixSwagger(swagger);
console.log(fixedSwagger);
// {
//   swagger: '2.0',
//   info: {
//     title: 'API',
//     version: '1.0.0',
//   },
//   paths: {
//     '/api': {
//       get: {
//         operationId: 'huoQuShuJu',
//         responses: {
//           200: {
//             $ref: '#/definitions/shuJu',
//           },
//         },
//       },
//     },
//   },
//   definitions: {
//     shuJu: {
//       type: 'object',
//       properties: {
//         name: {
//           type: 'string',
//         },
//       },
//     },
//   },
// };

Package Sidebar

Install

npm i swagger-fix

Weekly Downloads

30

Version

1.0.3

License

MIT

Unpacked Size

60.4 kB

Total Files

11

Last publish

Collaborators

  • val.istar.guo