🇺🇸 English | 🇷🇺 Русский | 🇨🇳 中文
This example demonstrates how to use openapi-modifier to modify OpenAPI specification and subsequently generate TypeScript types.
In this example, we:
- Modify the input OpenAPI file using
openapi-modifier - Generate TypeScript types from the modified OpenAPI file
example-cli-simple-generate-api-types/
├── input/
│ └── openapi.yaml # Input OpenAPI file
├── output/
│ ├── openapi.yaml # Modified OpenAPI file
│ └── generated-api-types.d.ts # Generated TypeScript types
├── openapi-modifier.config.ts # openapi-modifier configuration
└── package.json # Dependencies and scripts
The openapi-modifier.config.ts file defines the following modification rules:
-
Base Path Modification:
- Removing
/api/externalprefix from API paths
- Removing
-
Endpoint Filtering:
- Removing all paths containing
/internal
- Removing all paths containing
-
Unused Components Removal:
- Cleaning up schemas that are not used in the API
- Install dependencies:
npm install- Run the modification and type generation process:
npm startThis will execute the following steps:
- Modify the input OpenAPI file (
prepare-input-openapi) - Generate TypeScript types from the modified file (
generate-api-types)
After running the scripts, the following files will be created in the output/ directory:
openapi.yaml- modified version of OpenAPI specificationgenerated-api-types.d.ts- generated TypeScript types
openapi-modifier- for modifying OpenAPI specificationdtsgenerator- for generating TypeScript types