Skip to content

hey-api Plugin

The @nx-plugin-openapi/plugin-hey-api plugin integrates hey-api/openapi-ts with the Nx Plugin OpenAPI ecosystem.

Terminal window
# Install the core package and plugin
npm install --save-dev @nx-plugin-openapi/core @nx-plugin-openapi/plugin-hey-api
# Install the peer dependency
npm install --save-dev @hey-api/openapi-ts
project.json
{
"targets": {
"generate-api": {
"executor": "@nx-plugin-openapi/core:generate-api",
"options": {
"generator": "hey-api",
"inputSpec": "apps/my-app/openapi.yaml",
"outputPath": "libs/api-client/src"
}
}
}
}

Pass hey-api specific options via the generatorOptions property or directly in options.

OptionTypeDescription
generatorstringMust be "hey-api"
inputSpecstringPath to OpenAPI spec (local or URL)
outputPathstringOutput directory for generated code
OptionTypeDescription
clientstringHTTP client to use ("fetch", "axios", etc.)
pluginsarrayArray of hey-api plugins to enable
schemasobjectSchema generation options
servicesobjectService generation options
typesobjectType generation options

hey-api supports multiple HTTP clients:

{
"generator": "hey-api",
"inputSpec": "openapi.yaml",
"outputPath": "libs/api-client/src",
"generatorOptions": {
"client": "@hey-api/client-fetch"
}
}
{
"generatorOptions": {
"client": "@hey-api/client-axios"
}
}

hey-api has a plugin system for customizing output:

{
"generator": "hey-api",
"inputSpec": "openapi.yaml",
"outputPath": "libs/api-client/src",
"generatorOptions": {
"client": "@hey-api/client-fetch",
"plugins": [
"@hey-api/schemas",
"@hey-api/services",
{
"name": "@hey-api/types",
"enums": "javascript"
}
]
}
}
PluginDescription
@hey-api/schemasGenerate JSON schemas
@hey-api/servicesGenerate service functions
@hey-api/typesGenerate TypeScript types
@hey-api/transformersTransform request/response data
@tanstack/react-queryReact Query integration
@tanstack/vue-queryVue Query integration

hey-api has excellent TanStack Query support:

{
"generatorOptions": {
"client": "@hey-api/client-fetch",
"plugins": [
"@hey-api/services",
"@hey-api/types",
"@tanstack/react-query"
]
}
}
{
"generatorOptions": {
"client": "@hey-api/client-fetch",
"plugins": [
"@hey-api/services",
"@hey-api/types",
"@tanstack/vue-query"
]
}
}

Customize how types are generated:

{
"generatorOptions": {
"plugins": [
{
"name": "@hey-api/types",
"enums": "javascript",
"exportInlineEnums": true
}
]
}
}
ValueDescription
"javascript"Generate JavaScript enums
"typescript"Generate TypeScript enums
falseUse union types instead of enums
project.json
{
"targets": {
"generate-api": {
"executor": "@nx-plugin-openapi/core:generate-api",
"options": {
"generator": "hey-api",
"inputSpec": "apps/my-app/openapi.yaml",
"outputPath": "libs/api-client/src/generated",
"generatorOptions": {
"client": "@hey-api/client-fetch",
"plugins": [
"@hey-api/schemas",
{
"name": "@hey-api/services",
"asClass": true
},
{
"name": "@hey-api/types",
"enums": "javascript"
}
]
}
}
}
}
}
  • TypeScript-first: Designed from the ground up for TypeScript
  • Tree-shakeable: Only import what you use
  • Modern output: ESM modules, no legacy code
  • Type safety: Excellent type inference
  • Plugin system: Extensible architecture
  • Active development: Regular updates and improvements
Featurehey-apiOpenAPI Generator
LanguagesTypeScript only50+ languages
Output sizeSmaller, tree-shakeableLarger, more complete
Type safetyExcellentGood
Angular supportBasicExcellent (injectable services)
CustomizationPluginsTemplates
Java requiredNoYes