Getting Started
genapi is a lightweight API code generator that generates only the code you need—nothing extra.
Installation
Use the init command to quickly generate a genapi config file:
npx genapi init
yarn dlx genapi init
pnpm dlx genapi init
bunx genapi init
deno run -A npm:genapi init
Or install dependencies manually:
npm i @genapi/core @genapi/presets
yarn add @genapi/core @genapi/presets
pnpm i @genapi/core @genapi/presets
bun i @genapi/core @genapi/presets
deno i npm:@genapi/core @genapi/presets
Running init starts an interactive wizard:
Choose Preset: fetch, ofetch, axios, ky, got, @tanstack/react-query, @tanstack/vue-query, @pinia/colada, @uni-helper/uni-network
Overwrite confirmation: If genapi.config.ts already exists, you'll be asked whether to overwrite
Dependencies: @genapi/core and @genapi/presets are installed automatically; Schema mode also adds fetchdts
This creates genapi.config.ts or genapi.config.js in the project root. Then update input to your API doc URL.
Basic Usage
Create a config file genapi.config.ts in your project root:
import { defineConfig } from '@genapi/core'
import { axios } from '@genapi/presets'
export default defineConfig({
// preset: pipeline object (e.g. axios.ts) or string (e.g. 'swag-axios-ts')
preset: axios.ts,
input: 'https://petstore3.swagger.io/api/v3/openapi.json',
output: {
main: 'src/api/index.ts',
type: 'src/api/index.type.ts',
},
meta: {
baseURL: 'import.meta.env.VITE_APP_BASE_API',
// responseType: 'T extends { data?: infer V } ? V : void',
},
})
Then run to generate API code like:
npx genapi
import type { AxiosRequestConfig } from 'axios'
import type * as Types from './index.type'
import http from 'axios'
/** Update an existing pet by Id. */
export function putPet(data?: Types.Pet, config?: AxiosRequestConfig) {
return http.request<Types.Pet>({ method: 'put', url: '/pet', data, ...config })
}
/** Add a new pet to the store. */
export function postPet(data?: Types.Pet, config?: AxiosRequestConfig) {
return http.request<Types.Pet>({ method: 'post', url: '/pet', data, ...config })
}
Features
- 🚀 Multiple HTTP Clients - axios, fetch, ky, got, ofetch, uni and more
- 📡 Data Layer Presets - TanStack React Query, Vue Query, Pinia Colada (fetcher + useQuery/useMutation)
- 🔄 Language Support - Generate TypeScript or JavaScript APIs
- 🛠️ Customizable - Flexible pipeline for custom generation
- 📋 Multiple Data Sources - OpenAPI 2.0/3.x, Swagger and more
Next Steps
Check out the Configuration Guide to learn more about configuration options.