🇺🇸 English | 🇷🇺 Русский | 🇨🇳 中文
This example demonstrates using openapi-modifier to convert OpenAPI specification from YAML to JSON format while applying modification rules.
example-cli-openapi-yaml-to-json/
├── input/
│ └── openapi.yml # Input OpenAPI file in YAML format
├── output/
│ └── openapi.json # Output OpenAPI file in JSON format
├── openapi-modifier.config.ts # Modification rules configuration
└── package.json # Project dependencies
npm installThe openapi-modifier.config.ts file defines a rule to remove operationId from all API operations:
import { ConfigT } from 'openapi-modifier';
const config: ConfigT = {
pipeline: [
{
rule: 'remove-operation-id',
config: {
ignore: [],
},
},
],
};
export default config;To run the conversion:
npm startor directly:
openapi-modifier --input=input/openapi.yml --output=output/openapi.jsonAfter executing the command:
- The
input/openapi.ymlfile will be read - Modification rules will be applied (in this case - removal of all
operationId) - The result will be saved to
output/openapi.jsonin JSON format
- Input file must be in YAML format
- Output file will be created in JSON format
- All modification rules are applied in the order they are defined in the configuration file