hey-api-plugin-additional-types
v0.0.2
Published
A custom Hey API plugin that generates TypeScript union types for all tags and operation IDs found in your OpenAPI schema.
Readme
additionalTypes Plugin
A custom Hey API plugin that generates TypeScript union types for all tags and operation IDs found in your OpenAPI schema.
Its main purpose is to provide strongly-typed constants for use with React Query meta invalidation — so instead of plain strings you get compile-time safety when referencing tags or operation IDs.
Generated output
Given an OpenAPI schema with operations tagged users, products, and operation IDs getUsers, createUser, the plugin generates:
// additionalTypes.gen.ts
export type AvailableTags = 'products' | 'users';
export type AvailableOperationIds = 'createUser' | 'getUsers';Both unions are sorted alphabetically. If no tags / operation IDs exist in the schema, the type falls back to never.
Installation
npm install hey-api-plugin-additional-types
your-project/
├── openapi-ts.config.ts
└── src/
└── client/ ← generated outputUsage
// openapi-ts.config.ts
import { defineConfig } from '@hey-api/openapi-ts';
import additionalTypesConfig from 'hey-api-plugin-additional-types';
export default defineConfig({
input: './openapi.yaml',
output: 'src/client',
plugins: [
'@hey-api/typescript',
additionalTypesConfig({
generateTags:true,
generateOperationIds:true,
tagsTypeName:'AvailableTags',
operationIdsTypeName:'AvailableOperationIds'
}),
],
});With options
additionalTypesConfig({
generateTags: true,
generateOperationIds: false,
tagsTypeName: 'ApiTag',
})Options
| Option | Type | Default | Description |
|-----------------------|-----------|--------------------------|------------------------------------------------------|
| generateTags | boolean | true | Generate union type of all operation tags |
| generateOperationIds| boolean | true | Generate union type of all operation IDs |
| tagsTypeName | string | 'AvailableTags' | Name of the generated tags union type |
| operationIdsTypeName| string | 'AvailableOperationIds'| Name of the generated operation IDs union type |
