@genapi/core
v4.1.0
Published
<!-- automd:badges -->
Readme
@genapi/core
CLI and config entry for generating TypeScript/JavaScript API code from OpenAPI/Swagger and other inputs.
Installation
pnpm add -D @genapi/core @genapi/presetsUsage
Create genapi.config.ts or genapi.config.js in your project root, then run the genapi command.
API
Core
generate(config)
Runs the GenAPI pipeline for one or more configs. Resolves pipeline by name (e.g. swag-axios-ts), then runs config → original → parser → compiler → generate → dest.
Example:
await generate(defineConfig({ preset: 'swag-axios-ts', input: 'openapi.json', output: { main: 'src/api.ts' } }))
await generate([config1, config2])Inject
inject(scope)
Gets the current pipeline context for the given scope (default: 'default'). Used inside pipeline steps to read config/graphs.
Example:
const { configRead, interfaces } = inject()
const config = inject('get/user/1')absolutePath(_path)
Resolves a path to an absolute path; relative paths are resolved against cwd().
Example:
absolutePath('./presets/axios') // path.resolve(cwd(), './presets/axios')
absolutePath('/etc/config') // '/etc/config'ApiPipeline
- Type:
undefined - Default:
undefined
context
- Type:
any - Default:
{}
defineConfig(config)
Defines GenAPI config for genapi.config.ts / genapi.config.js. Supports single-service config or multi-service servers config.
Example:
export default defineConfig({
preset: axios.ts,
input: 'http://example.com/api-docs',
output: { main: 'src/api/index.ts', type: 'src/api/index.type.ts' },
})inPipeline(pipe)
Resolves a pipeline from a preset name or function. Tries @genapi/presets/{name}, genapi-{name}, then local path.
Example:
const pipeline = await inPipeline('swag-axios-ts')
await pipeline(config)provide()
License
🤖 auto updated with automd
