Skip to content

Commit 80dc015

Browse files
committed
chore: cleanup
1 parent 4ae906d commit 80dc015

39 files changed

+3272
-3950
lines changed

.changeset/modern-colts-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
feat(plugin): add `@pinia/colada` plugin

packages/openapi-ts-tests/main/test/openapi-ts.config.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export default defineConfig(() => {
3636
'3.1.x',
3737
// 'invalid',
3838
// 'openai.yaml',
39-
// 'full.yaml',
39+
'full.yaml',
4040
// 'opencode.yaml',
41-
'zoom-video-sdk.json',
41+
// 'zoom-video-sdk.json',
4242
),
4343
// https://registry.scalar.com/@lubos-heyapi-dev-team/apis/demo-api-scalar-galaxy/latest?format=json
4444
// path: 'scalar:@lubos-heyapi-dev-team/demo-api-scalar-galaxy',
@@ -81,7 +81,7 @@ export default defineConfig(() => {
8181
// deprecated: false,
8282
operations: {
8383
include: [
84-
'GET /event',
84+
// 'GET /event',
8585
// '/^[A-Z]+ /v1//',
8686
],
8787
},
@@ -94,6 +94,11 @@ export default defineConfig(() => {
9494
// exclude: ['bar'],
9595
// },
9696
},
97+
hooks: {
98+
operations: {
99+
// isMutation: () => true,
100+
},
101+
},
97102
pagination: {
98103
// keywords: ['aa'],
99104
},
@@ -171,7 +176,7 @@ export default defineConfig(() => {
171176
// responseStyle: 'data',
172177
// transformer: '@hey-api/transformers',
173178
// transformer: true,
174-
validator: 'valibot',
179+
// validator: 'valibot',
175180
// validator: {
176181
// request: 'zod',
177182
// response: 'zod',
@@ -198,7 +203,7 @@ export default defineConfig(() => {
198203
// mutationOptions: {
199204
// name: '{{name}}MO',
200205
// },
201-
name: '@tanstack/react-query',
206+
// name: '@tanstack/react-query',
202207
// queryKeys: {
203208
// name: '{{name}}QK',
204209
// },
@@ -212,7 +217,7 @@ export default defineConfig(() => {
212217
definitions: 'z{{name}}Definition',
213218
exportFromIndex: true,
214219
metadata: true,
215-
name: 'valibot',
220+
// name: 'valibot',
216221
requests: {
217222
// case: 'SCREAMING_SNAKE_CASE',
218223
name: 'z{{name}}TestData',
@@ -241,7 +246,7 @@ export default defineConfig(() => {
241246
},
242247
exportFromIndex: true,
243248
metadata: true,
244-
name: 'zod',
249+
// name: 'zod',
245250
// requests: {
246251
// // case: 'SCREAMING_SNAKE_CASE',
247252
// // name: 'z{{name}}TestData',
@@ -273,6 +278,14 @@ export default defineConfig(() => {
273278
exportFromIndex: true,
274279
// name: '@angular/common',
275280
},
281+
{
282+
name: '@pinia/colada',
283+
'~hooks': {
284+
operations: {
285+
// isQuery: () => true,
286+
},
287+
},
288+
},
276289
],
277290
// useOptions: false,
278291
// watch: 3_000,

packages/openapi-ts-tests/main/test/plugins/@pinia/colada-functional.test.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url';
55
import { createClient } from '@hey-api/openapi-ts';
66
import { describe, expect, it, vi } from 'vitest';
77

8-
import { getSpecsPath } from '../../../utils';
8+
import { getSpecsPath } from '../../../../utils';
99

1010
const __filename = fileURLToPath(import.meta.url);
1111
const __dirname = path.dirname(__filename);
@@ -71,25 +71,6 @@ describe('@pinia/colada functional tests', () => {
7171
expect(typeof mutationOptions.mutation).toBe('function');
7272
});
7373

74-
it('should respect autoDetectHttpMethod setting', async () => {
75-
const piniaColadaDefault = await setupPiniaColadaTest({
76-
autoDetectHttpMethod: true,
77-
});
78-
79-
// With auto-detection, GET should be query, POST should be mutation
80-
expect(piniaColadaDefault.getPetByIdQuery).toBeDefined(); // GET -> query
81-
expect(piniaColadaDefault.addPetMutation).toBeDefined(); // POST -> mutation
82-
expect(piniaColadaDefault.addPetQuery).toBeUndefined(); // POST should not generate query
83-
84-
const piniaColadaDisabled = await setupPiniaColadaTest({
85-
autoDetectHttpMethod: false,
86-
});
87-
88-
// With auto-detection disabled, both GET and POST should generate queries (legacy behavior)
89-
expect(piniaColadaDisabled.getPetByIdQuery).toBeDefined();
90-
// Note: The legacy behavior test might need adjustment based on actual implementation
91-
});
92-
9374
it('should respect operation type overrides', async () => {
9475
const piniaColada = await setupPiniaColadaTest({
9576
operationTypes: {

packages/openapi-ts-tests/main/test/plugins/@pinia/colada-integration.test.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url';
55
import { createClient, type UserConfig } from '@hey-api/openapi-ts';
66
import { describe, expect, it } from 'vitest';
77

8-
import { getFilePaths, getSpecsPath } from '../../../utils';
8+
import { getFilePaths, getSpecsPath } from '../../../../utils';
99

1010
const __filename = fileURLToPath(import.meta.url);
1111
const __dirname = path.dirname(__filename);
@@ -14,16 +14,22 @@ const version = '3.1.x';
1414
const outputDir = path.join(__dirname, 'generated', version, 'integration');
1515

1616
describe('@pinia/colada integration tests', () => {
17-
const createConfig = (userConfig: UserConfig): UserConfig => {
17+
const createConfig = (
18+
userConfig: Omit<UserConfig, 'input'> & Pick<Partial<UserConfig>, 'input'>,
19+
): UserConfig => {
1820
const inputPath = path.join(getSpecsPath(), version, 'petstore.yaml');
1921
return {
20-
input: inputPath,
21-
logs: { level: 'silent' },
22-
output: path.join(
23-
outputDir,
24-
typeof userConfig.output === 'string' ? userConfig.output : '',
25-
),
22+
logs: {
23+
level: 'silent',
24+
},
2625
...userConfig,
26+
input: userConfig.input ?? inputPath,
27+
output:
28+
userConfig.output ??
29+
path.join(
30+
outputDir,
31+
typeof userConfig.output === 'string' ? userConfig.output : '',
32+
),
2733
};
2834
};
2935

@@ -70,6 +76,7 @@ describe('@pinia/colada integration tests', () => {
7076
'@hey-api/client-fetch',
7177
{
7278
name: '@hey-api/sdk',
79+
// @ts-expect-error
7380
transformer: {
7481
name: 'custom',
7582
},
@@ -113,6 +120,7 @@ describe('@pinia/colada integration tests', () => {
113120
plugins: [
114121
'@hey-api/client-fetch',
115122
{
123+
// @ts-expect-error
116124
case: 'PascalCase',
117125
name: '@hey-api/sdk',
118126
},

packages/openapi-ts-tests/main/test/plugins/@pinia/colada-meta-functions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url';
55
import { createClient, type UserConfig } from '@hey-api/openapi-ts';
66
import { describe, expect, it } from 'vitest';
77

8-
import { getFilePaths, getSpecsPath } from '../../../utils';
8+
import { getFilePaths, getSpecsPath } from '../../../../utils';
99

1010
const __filename = fileURLToPath(import.meta.url);
1111
const __dirname = path.dirname(__filename);

packages/openapi-ts/src/config/parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const defaultPaginationKeywords = [
1313
export const getParser = (userConfig: UserConfig): Config['parser'] => {
1414
const parser: Config['parser'] = {
1515
...userConfig.parser,
16+
hooks: {},
1617
pagination: {
1718
keywords: defaultPaginationKeywords,
1819
},

packages/openapi-ts/src/ir/context.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,12 @@ import { GeneratedFile } from '../generate/file';
66
import type { PluginConfigMap } from '../plugins/config';
77
import { PluginInstance } from '../plugins/shared/utils/instance';
88
import type { PluginNames } from '../plugins/types';
9-
import type { StringCase } from '../types/case';
109
import type { Config } from '../types/config';
1110
import type { Files } from '../types/utils';
1211
import type { Logger } from '../utils/logger';
1312
import { resolveRef } from '../utils/ref';
1413
import type { IR } from './types';
1514

16-
export interface ContextFile {
17-
/**
18-
* Define casing for identifiers in this file.
19-
*/
20-
case?: StringCase;
21-
/**
22-
* Should the exports from this file be re-exported in the index barrel file?
23-
*/
24-
exportFromIndex?: boolean;
25-
/**
26-
* Unique file identifier.
27-
*/
28-
id: string;
29-
/**
30-
* Relative file path to the output path.
31-
*
32-
* @example
33-
* 'bar/foo.ts'
34-
*/
35-
path: string;
36-
}
37-
3815
export class IRContext<Spec extends Record<string, any> = any> {
3916
/**
4017
* Configuration for parsing and generating the output. This
@@ -92,7 +69,7 @@ export class IRContext<Spec extends Record<string, any> = any> {
9269
* Create and return a new TypeScript file. Also set the current file context
9370
* to the newly created file.
9471
*/
95-
public createFile(file: ContextFile): GeneratedFile {
72+
public createFile(file: IR.ContextFile): GeneratedFile {
9673
// TODO: parser - handle attempt to create duplicate
9774
const outputParts = file.path.split('/');
9875
const outputDir = path.resolve(
@@ -127,7 +104,7 @@ export class IRContext<Spec extends Record<string, any> = any> {
127104
/**
128105
* Returns a specific file by ID from `files`.
129106
*/
130-
public file({ id }: Pick<ContextFile, 'id'>): GeneratedFile | undefined {
107+
public file({ id }: Pick<IR.ContextFile, 'id'>): GeneratedFile | undefined {
131108
return this.files[id];
132109
}
133110

packages/openapi-ts/src/ir/types.d.ts

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import type {
33
SecuritySchemeObject,
44
ServerObject,
55
} from '../openApi/3.1.x/types/spec';
6-
import type { ContextFile as CtxFile, IRContext } from './context';
6+
import type { StringCase } from '../types/case';
7+
import type { IRContext } from './context';
78
import type { IRMediaType } from './mediaType';
89

910
interface IRBodyObject {
@@ -24,6 +25,86 @@ interface IRComponentsObject {
2425
schemas?: Record<string, IRSchemaObject>;
2526
}
2627

28+
interface IRContextFile {
29+
/**
30+
* Define casing for identifiers in this file.
31+
*/
32+
case?: StringCase;
33+
/**
34+
* Should the exports from this file be re-exported in the index barrel file?
35+
*/
36+
exportFromIndex?: boolean;
37+
/**
38+
* Unique file identifier.
39+
*/
40+
id: string;
41+
/**
42+
* Relative file path to the output path.
43+
*
44+
* @example
45+
* 'bar/foo.ts'
46+
*/
47+
path: string;
48+
}
49+
50+
interface IRHooks {
51+
/**
52+
* Hooks specifically for overriding operations behavior.
53+
*
54+
* Use these to classify operations, decide which outputs to generate,
55+
* or apply custom behavior to individual operations.
56+
*/
57+
operations?: {
58+
/**
59+
* Classify the given operation into one or more kinds.
60+
*
61+
* Each kind determines how we treat the operation (e.g., generating queries or mutations).
62+
*
63+
* **Default behavior:**
64+
* - GET → 'query'
65+
* - DELETE, PATCH, POST, PUT → 'mutation'
66+
*
67+
* **Resolution order:**
68+
* 1. If `isQuery` or `isMutation` returns `true` or `false`, that overrides `getKind`.
69+
* 2. If `isQuery` or `isMutation` returns `undefined`, the result of `getKind` is used.
70+
*
71+
* @param operation - The operation object to classify.
72+
* @returns An array containing one or more of 'query' or 'mutation'.
73+
*/
74+
getKind?: (
75+
operation: IROperationObject,
76+
) => ReadonlyArray<'mutation' | 'query'>;
77+
/**
78+
* Check if the given operation should be treated as a mutation.
79+
*
80+
* This affects which outputs are generated for the operation.
81+
*
82+
* **Default behavior:** DELETE, PATCH, POST, and PUT operations are treated as mutations.
83+
*
84+
* **Resolution order:** If this returns `true` or `false`, it overrides `getKind`.
85+
* If it returns `undefined`, `getKind` is used instead.
86+
*
87+
* @param operation - The operation object to check.
88+
* @returns true if the operation is a mutation, false otherwise, or undefined to fallback to `getKind`.
89+
*/
90+
isMutation?: (operation: IROperationObject) => boolean | undefined;
91+
/**
92+
* Check if the given operation should be treated as a query.
93+
*
94+
* This affects which outputs are generated for the operation.
95+
*
96+
* **Default behavior:** GET operations are treated as queries.
97+
*
98+
* **Resolution order:** If this returns `true` or `false`, it overrides `getKind`.
99+
* If it returns `undefined`, `getKind` is used instead.
100+
*
101+
* @param operation - The operation object to check.
102+
* @returns true if the operation is a query, false otherwise, or undefined to fallback to `getKind`.
103+
*/
104+
isQuery?: (operation: IROperationObject) => boolean | undefined;
105+
};
106+
}
107+
27108
interface IROperationObject {
28109
body?: IRBodyObject;
29110
deprecated?: boolean;
@@ -221,7 +302,8 @@ export namespace IR {
221302
export type BodyObject = IRBodyObject;
222303
export type ComponentsObject = IRComponentsObject;
223304
export type Context<Spec extends Record<string, any> = any> = IRContext<Spec>;
224-
export type ContextFile = CtxFile;
305+
export type ContextFile = IRContextFile;
306+
export type Hooks = IRHooks;
225307
export type Model = IRModel;
226308
export type OperationObject = IROperationObject;
227309
export type ParameterObject = IRParameterObject;

0 commit comments

Comments
 (0)