openapi-import
Import an OpenAPI spec in TypeScript like any other file, with types, autocomplete, and errors from the spec and no generated files.
#typescript #openapi #kubb #content-mapper
Highlights
TypeScript 7.1
Import the spec, get the types
"contentMappers": [{ "package": "openapi-import", "extensions": [".openapi.yaml", ".openapi.yml"] }]One line in tsconfig.json
Go to definition
Jump from a type to its schema in the YAML.
- 0
Generated files
The types come straight from the spec.
- pluginTspluginZodpluginClient
Add kubb.config.ts for more
Zod schemas and clients come from the same import.
tsc --runExternalCodeChecked in CI too
The same errors in the editor and in the build.
openapi-import is a TypeScript 7.1 content mapper. Register it in tsconfig.json, then import a spec:
import type { Pet } from './petStore.openapi.yaml'
Features
- Types straight from the spec, with no generated files.
- Works without a config: you get the types from Kubb's
pluginTs. - Add a
kubb.config.tsto get Zod schemas, clients and other plugin output from the same import. - Autocomplete and type errors come from the spec.
- Go to definition, find references and hover jump between the types and the YAML.
- Rename a schema type and the key in the spec is renamed too.
tsc --runExternalCodereports the same errors in CI.- At run time,
unplugin-kubbloads the same module in Vite, webpack, Rollup and other bundlers.