···11-import type { Symbol } from '@hey-api/codegen-core';
22-31import type { JsonSchemaDraft2020_12 } from '~/openApi/3.1.x/types/json-schema-draft-2020-12';
42import type {
53 SecuritySchemeObject,
···2725 schemas?: Record<string, IRSchemaObject>;
2826}
29273030-interface IRHooks {
3131- /**
3232- * Hooks specifically for overriding operations behavior.
3333- *
3434- * Use these to classify operations, decide which outputs to generate,
3535- * or apply custom behavior to individual operations.
3636- */
3737- operations?: {
3838- /**
3939- * Classify the given operation into one or more kinds.
4040- *
4141- * Each kind determines how we treat the operation (e.g., generating queries or mutations).
4242- *
4343- * **Default behavior:**
4444- * - GET → 'query'
4545- * - DELETE, PATCH, POST, PUT → 'mutation'
4646- *
4747- * **Resolution order:**
4848- * 1. If `isQuery` or `isMutation` returns `true` or `false`, that overrides `getKind`.
4949- * 2. If `isQuery` or `isMutation` returns `undefined`, the result of `getKind` is used.
5050- *
5151- * @param operation - The operation object to classify.
5252- * @returns An array containing one or more of 'query' or 'mutation', or undefined to fallback to default behavior.
5353- * @example
5454- * getKind: (operation) => {
5555- * if (operation.method === 'get' && operation.path === '/search') {
5656- * return ['query', 'mutation'];
5757- * }
5858- * return; // fallback to default behavior
5959- * }
6060- */
6161- getKind?: (
6262- operation: IROperationObject,
6363- ) => ReadonlyArray<'mutation' | 'query'> | undefined;
6464- /**
6565- * Check if the given operation should be treated as a mutation.
6666- *
6767- * This affects which outputs are generated for the operation.
6868- *
6969- * **Default behavior:** DELETE, PATCH, POST, and PUT operations are treated as mutations.
7070- *
7171- * **Resolution order:** If this returns `true` or `false`, it overrides `getKind`.
7272- * If it returns `undefined`, `getKind` is used instead.
7373- *
7474- * @param operation - The operation object to check.
7575- * @returns true if the operation is a mutation, false otherwise, or undefined to fallback to `getKind`.
7676- * @example
7777- * isMutation: (operation) => {
7878- * if (operation.method === 'post' && operation.path === '/search') {
7979- * return true;
8080- * }
8181- * return; // fallback to default behavior
8282- }
8383- */
8484- isMutation?: (operation: IROperationObject) => boolean | undefined;
8585- /**
8686- * Check if the given operation should be treated as a query.
8787- *
8888- * This affects which outputs are generated for the operation.
8989- *
9090- * **Default behavior:** GET operations are treated as queries.
9191- *
9292- * **Resolution order:** If this returns `true` or `false`, it overrides `getKind`.
9393- * If it returns `undefined`, `getKind` is used instead.
9494- *
9595- * @param operation - The operation object to check.
9696- * @returns true if the operation is a query, false otherwise, or undefined to fallback to `getKind`.
9797- * @example
9898- * isQuery: (operation) => {
9999- * if (operation.method === 'post' && operation.path === '/search') {
100100- * return true;
101101- * }
102102- * return; // fallback to default behavior
103103- }
104104- */
105105- isQuery?: (operation: IROperationObject) => boolean | undefined;
106106- };
107107- /**
108108- * Hooks specifically for overriding symbols behavior.
109109- *
110110- * Use these to customize file placement.
111111- */
112112- symbols?: {
113113- /**
114114- * Optional output strategy to override default plugin behavior.
115115- *
116116- * Use this to route generated symbols to specific files.
117117- *
118118- * @returns The file path to output the symbol to, or undefined to fallback to default behavior.
119119- */
120120- getFilePath?: (symbol: Symbol) => string | undefined;
121121- };
122122-}
123123-124124-interface IROperationObject {
2828+export interface IROperationObject {
12529 body?: IRBodyObject;
12630 deprecated?: boolean;
12731 description?: string;
···318222 export type BodyObject = IRBodyObject;
319223 export type ComponentsObject = IRComponentsObject;
320224 export type Context<Spec extends Record<string, any> = any> = IRContext<Spec>;
321321- export type Hooks = IRHooks;
322225 export type Model = IRModel;
323226 export type OperationObject = IROperationObject;
324227 export type ParameterObject = IRParameterObject;
+189
packages/openapi-ts/src/parser/types/hooks.d.ts
···11+import type { Symbol, SymbolIn } from '@hey-api/codegen-core';
22+33+import type { IROperationObject } from '~/ir/types';
44+import type { PluginInstance } from '~/plugins/shared/utils/instance';
55+66+export type Hooks = {
77+ /**
88+ * Event hooks.
99+ */
1010+ events?: {
1111+ /**
1212+ * Triggered after executing a plugin handler.
1313+ *
1414+ * @param args Arguments object.
1515+ * @returns void
1616+ */
1717+ 'plugin:handler:after'?: (args: {
1818+ /** Plugin that just executed. */
1919+ plugin: PluginInstance;
2020+ }) => void;
2121+ /**
2222+ * Triggered before executing a plugin handler.
2323+ *
2424+ * @param args Arguments object.
2525+ * @returns void
2626+ */
2727+ 'plugin:handler:before'?: (args: {
2828+ /** Plugin about to execute. */
2929+ plugin: PluginInstance;
3030+ }) => void;
3131+ /**
3232+ * Triggered after registering a symbol.
3333+ *
3434+ * You can use this to perform actions after a symbol is registered.
3535+ *
3636+ * @param args Arguments object.
3737+ * @returns void
3838+ */
3939+ 'symbol:register:after'?: (args: {
4040+ /** Plugin that registered the symbol. */
4141+ plugin: PluginInstance;
4242+ /** The registered symbol. */
4343+ symbol: Symbol;
4444+ }) => void;
4545+ /**
4646+ * Triggered before registering a symbol.
4747+ *
4848+ * You can use this to modify the symbol before it's registered.
4949+ *
5050+ * @param args Arguments object.
5151+ * @returns void
5252+ */
5353+ 'symbol:register:before'?: (args: {
5454+ /** Plugin registering the symbol. */
5555+ plugin: PluginInstance;
5656+ /** Symbol to register. */
5757+ symbol: SymbolIn;
5858+ }) => void;
5959+ /**
6060+ * Triggered after setting a symbol value.
6161+ *
6262+ * You can use this to perform actions after a symbol's value is set.
6363+ *
6464+ * @param args Arguments object.
6565+ * @returns void
6666+ */
6767+ 'symbol:setValue:after'?: (args: {
6868+ /** Plugin that set the symbol value. */
6969+ plugin: PluginInstance;
7070+ /** The symbol. */
7171+ symbol: Symbol;
7272+ /** The value that was set. */
7373+ value: unknown;
7474+ }) => void;
7575+ /**
7676+ * Triggered before setting a symbol value.
7777+ *
7878+ * You can use this to modify the value before it's set.
7979+ *
8080+ * @param args Arguments object.
8181+ * @returns void
8282+ */
8383+ 'symbol:setValue:before'?: (args: {
8484+ /** Plugin setting the symbol value. */
8585+ plugin: PluginInstance;
8686+ /** The symbol. */
8787+ symbol: Symbol;
8888+ /** The value to set. */
8989+ value: unknown;
9090+ }) => void;
9191+ };
9292+ /**
9393+ * Hooks specifically for overriding operations behavior.
9494+ *
9595+ * Use these to classify operations, decide which outputs to generate,
9696+ * or apply custom behavior to individual operations.
9797+ */
9898+ operations?: {
9999+ /**
100100+ * Classify the given operation into one or more kinds.
101101+ *
102102+ * Each kind determines how we treat the operation (e.g., generating queries or mutations).
103103+ *
104104+ * **Default behavior:**
105105+ * - GET → 'query'
106106+ * - DELETE, PATCH, POST, PUT → 'mutation'
107107+ *
108108+ * **Resolution order:**
109109+ * 1. If `isQuery` or `isMutation` returns `true` or `false`, that overrides `getKind`.
110110+ * 2. If `isQuery` or `isMutation` returns `undefined`, the result of `getKind` is used.
111111+ *
112112+ * @param operation - The operation object to classify.
113113+ * @returns An array containing one or more of 'query' or 'mutation', or undefined to fallback to default behavior.
114114+ * @example
115115+ * ```ts
116116+ * getKind: (operation) => {
117117+ * if (operation.method === 'get' && operation.path === '/search') {
118118+ * return ['query', 'mutation'];
119119+ * }
120120+ * return; // fallback to default behavior
121121+ * }
122122+ * ```
123123+ */
124124+ getKind?: (
125125+ operation: IROperationObject,
126126+ ) => ReadonlyArray<'mutation' | 'query'> | undefined;
127127+ /**
128128+ * Check if the given operation should be treated as a mutation.
129129+ *
130130+ * This affects which outputs are generated for the operation.
131131+ *
132132+ * **Default behavior:** DELETE, PATCH, POST, and PUT operations are treated as mutations.
133133+ *
134134+ * **Resolution order:** If this returns `true` or `false`, it overrides `getKind`.
135135+ * If it returns `undefined`, `getKind` is used instead.
136136+ *
137137+ * @param operation - The operation object to check.
138138+ * @returns true if the operation is a mutation, false otherwise, or undefined to fallback to `getKind`.
139139+ * @example
140140+ * ```ts
141141+ * isMutation: (operation) => {
142142+ * if (operation.method === 'post' && operation.path === '/search') {
143143+ * return true;
144144+ * }
145145+ * return; // fallback to default behavior
146146+ * }
147147+ * ```
148148+ */
149149+ isMutation?: (operation: IROperationObject) => boolean | undefined;
150150+ /**
151151+ * Check if the given operation should be treated as a query.
152152+ *
153153+ * This affects which outputs are generated for the operation.
154154+ *
155155+ * **Default behavior:** GET operations are treated as queries.
156156+ *
157157+ * **Resolution order:** If this returns `true` or `false`, it overrides `getKind`.
158158+ * If it returns `undefined`, `getKind` is used instead.
159159+ *
160160+ * @param operation - The operation object to check.
161161+ * @returns true if the operation is a query, false otherwise, or undefined to fallback to `getKind`.
162162+ * @example
163163+ * ```ts
164164+ * isQuery: (operation) => {
165165+ * if (operation.method === 'post' && operation.path === '/search') {
166166+ * return true;
167167+ * }
168168+ * return; // fallback to default behavior
169169+ * }
170170+ * ```
171171+ */
172172+ isQuery?: (operation: IROperationObject) => boolean | undefined;
173173+ };
174174+ /**
175175+ * Hooks specifically for overriding symbols behavior.
176176+ *
177177+ * Use these to customize file placement.
178178+ */
179179+ symbols?: {
180180+ /**
181181+ * Optional output strategy to override default plugin behavior.
182182+ *
183183+ * Use this to route generated symbols to specific files.
184184+ *
185185+ * @returns The file path to output the symbol to, or undefined to fallback to default behavior.
186186+ */
187187+ getFilePath?: (symbol: Symbol) => string | undefined;
188188+ };
189189+};
···11import type { ValueToObject } from '~/config/utils/config';
22import type { Package } from '~/config/utils/package';
33-import type { IR } from '~/ir/types';
43import type { OpenApi as LegacyOpenApi } from '~/openApi';
44+import type { Hooks } from '~/parser/types/hooks';
55import type { PluginInstance } from '~/plugins/shared/utils/instance';
66import type { Client as LegacyClient } from '~/types/client';
77import type { Files } from '~/types/utils';
···6868 * Use these to classify resources, control which outputs are generated,
6969 * or provide custom behavior for specific resources.
7070 */
7171- '~hooks'?: IR.Hooks;
7171+ '~hooks'?: Hooks;
7272};
73737474/**
+3-3
packages/openapi-ts/src/types/parser.d.ts
···11-import type { IR } from '~/ir/types';
21import type {
32 OpenApiMetaObject,
43 OpenApiOperationObject,
···76 OpenApiResponseObject,
87 OpenApiSchemaObject,
98} from '~/openApi/types';
99+import type { Hooks } from '~/parser/types/hooks';
10101111import type { StringCase, StringName } from './case';
1212···2424 * Use these to classify resources, control which outputs are generated,
2525 * or provide custom behavior for specific resources.
2626 */
2727- hooks?: IR.Hooks;
2727+ hooks?: Hooks;
2828 /**
2929 * Pagination configuration.
3030 */
···206206 * Use these to classify resources, control which outputs are generated,
207207 * or provide custom behavior for specific resources.
208208 */
209209- hooks: IR.Hooks;
209209+ hooks: Hooks;
210210 /**
211211 * Pagination configuration.
212212 */