swagger-fix
v1.0.5
Published
Fix invalid content in swagger file
Downloads
66
Maintainers
Readme
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',
// },
// },
// },
// },
// };