中文 | English English Docs
A lightweight API code generator—only the code you need.
- 🚀 Multiple HTTP Clients - Support for axios, fetch, ky, got, ofetch, tanstack-query, uni
- 🔄 TypeScript & JavaScript - Generate both TS and JS APIs with full type definitions
- 📋 Schema Mode - Type-safe fetch APIs with schema-based typing (supports
fetchandofetchpresets) - 📖 Multiple Data Sources - Support for OpenAPI 2.0/3.x, Swagger and other input sources
- 🔧 Interactive CLI - Use
genapi initfor guided setup with preset selection - 🛠️ Customizable Pipeline - Flexible pipeline system for customizing the generation process
- 🔀 Transform & Patch - Batch transform operations and types, or make exact-match modifications
- 🎭 Mock Data - Automatically generate mock methods for each API function (requires
better-mock) - 🌐 Multiple Services - Support for projects with multiple API services via
serversconfiguration - ⚡️ Type Safety - Full TypeScript support with type inference and IntelliSense
- 📦 Zero Config - Works out of the box with sensible defaults, customize as needed
Just run the following command to init your project:
# pnpm (recommended)
pnpm dlx @genapi/core genapi init
# npx @genapi/core genapi init
# yarn dlx @genapi/core genapi initOr install and configure manually:
pnpm i @genapi/core @genapi/presets -DCreate genapi.config.ts:
import { defineConfig } from '@genapi/core'
import { axios } from '@genapi/presets'
export default defineConfig({
preset: axios.ts,
input: 'https://petstore3.swagger.io/api/v3/openapi.json',
output: {
main: 'src/api/index.ts',
type: 'src/api/index.type.ts',
},
})Then run to generate API code like:
npx genapi/*
* @title Swagger Petstore - OpenAPI 3.0
* ... other metadata ...
*/
import type { AxiosRequestConfig } from 'axios'
import type * as Types from './index.type'
import http from 'axios'
/**
* @summary Update an existing pet.
* @description Update an existing pet by Id.
* @method put
* @tags pet
*/
export function putPet(data?: Types.Pet, config?: AxiosRequestConfig) {
const url = '/pet'
return http.request<Types.Pet>({ method: 'put', url, data, ...config })
}
/**
* @summary Add a new pet to the store.
* @description Add a new pet to the store.
* @method post
* @tags pet
*/
export function postPet(data?: Types.Pet, config?: AxiosRequestConfig) {
const url = '/pet'
return http.request<Types.Pet>({ method: 'post', url, data, ...config })
}For more details and features, visit the documentation site.