Skip to content

Commit 2e237c3

Browse files
authored
Merge pull request #2923 from hey-api/fix/types-context
fix: bundled context types
2 parents a7697da + f5a91c4 commit 2e237c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+194
-212
lines changed

.changeset/whole-parts-tan.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+
fix: bundled context types

dev/playground.ts

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,14 @@
1-
import { Sdk } from './.gen/sdk.gen';
1+
import type { DefinePlugin, IR } from '@hey-api/openapi-ts';
22

3-
const opencode = new Sdk();
4-
opencode.session.create(
5-
{
6-
parentID: '',
7-
title: '',
8-
},
9-
{
10-
headers: {
11-
'X-Custom-Header': 'value',
12-
},
13-
},
14-
);
15-
opencode.session.init({
16-
id: '',
17-
messageID: '',
18-
modelID: '',
19-
providerID: '',
20-
});
21-
opencode.session.chat({
22-
agent: '',
23-
id: '',
24-
messageID: '',
25-
modelID: '',
26-
parts: [
27-
{
28-
name: '',
29-
type: 'agent',
30-
},
31-
],
32-
providerID: '',
33-
system: '',
34-
tools: {},
35-
});
36-
opencode.auth.set({
37-
auth: {
38-
// access: '',
39-
// expires: 1,
40-
key: '',
41-
// refresh: '',
42-
// token: '',
43-
type: 'api',
44-
},
45-
id: '123',
46-
});
47-
opencode.postSessionByIdPermissionsByPermissionId({
48-
id: 'session-id',
49-
permissionID: 'permission-id',
50-
response: 'always',
51-
});
52-
opencode.tui.showToast({
53-
message: '',
54-
title: '',
55-
variant: 'error',
56-
});
3+
type MyPluginConfig = { readonly name: 'myplugin' };
4+
type MyPlugin = DefinePlugin<MyPluginConfig>;
5+
6+
export function f(schema: IR.SchemaObject, plugin: MyPlugin['Instance']) {
7+
plugin.context.resolveIrRef(schema.$ref);
8+
}
9+
10+
export const handler: MyPlugin['Handler'] = ({ plugin }) => {
11+
plugin.forEach('schema', 'operation', (event) => {
12+
console.log(event);
13+
});
14+
};

packages/openapi-ts/src/createClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import colors from 'ansi-colors';
66
import { generateLegacyOutput } from '~/generate/legacy/output';
77
import { generateOutput } from '~/generate/output';
88
import { getSpec } from '~/getSpec';
9-
import type { IR } from '~/ir/types';
9+
import type { Context } from '~/ir/context';
1010
import { parseLegacy, parseOpenApiSpec } from '~/openApi';
1111
import { buildGraph } from '~/openApi/shared/utils/graph';
1212
import { patchOpenApiSpec } from '~/openApi/shared/utils/patch';
@@ -254,7 +254,7 @@ export const createClient = async ({
254254
* Always undefined on the first run, defined on subsequent runs.
255255
*/
256256
watches?: ReadonlyArray<WatchValues>;
257-
}): Promise<Client | undefined | IR.Context> => {
257+
}): Promise<Client | undefined | Context> => {
258258
const watches: ReadonlyArray<WatchValues> =
259259
_watches ||
260260
Array.from({ length: config.input.length }, () => ({
@@ -296,7 +296,7 @@ export const createClient = async ({
296296
).filter((data) => data.arrayBuffer || data.resolvedInput);
297297

298298
let client: Client | undefined;
299-
let context: IR.Context | undefined;
299+
let context: Context | undefined;
300300

301301
if (specData.length) {
302302
const refParser = new $RefParser();

packages/openapi-ts/src/generate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
printCrashReport,
1212
shouldReportCrash,
1313
} from '~/error';
14-
import type { IR } from '~/ir/types';
14+
import type { Context } from '~/ir/context';
1515
import type { Client } from '~/types/client';
1616
import type { UserConfig } from '~/types/config';
1717
import type { LazyOrAsync, MaybeArray } from '~/types/utils';
@@ -27,7 +27,7 @@ import { Logger } from '~/utils/logger';
2727
export const createClient = async (
2828
userConfig?: LazyOrAsync<MaybeArray<UserConfig>>,
2929
logger = new Logger(),
30-
): Promise<ReadonlyArray<Client | IR.Context>> => {
30+
): Promise<ReadonlyArray<Client | Context>> => {
3131
const resolvedConfig =
3232
typeof userConfig === 'function' ? await userConfig() : userConfig;
3333
const userConfigs = resolvedConfig
@@ -90,7 +90,7 @@ export const createClient = async (
9090
}),
9191
);
9292
const result = clients.filter((client) => Boolean(client)) as ReadonlyArray<
93-
Client | IR.Context
93+
Client | Context
9494
>;
9595

9696
eventCreateClient.timeEnd();

packages/openapi-ts/src/generate/output.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import path from 'node:path';
33

44
import type { ProjectRenderMeta } from '@hey-api/codegen-core';
55

6-
import type { IR } from '~/ir/types';
6+
import type { Context } from '~/ir/context';
77
import { getClientPlugin } from '~/plugins/@hey-api/client-core/utils';
88

99
import { generateClientBundle } from './client';
1010
import { removeDirSync } from './utils';
1111

12-
export const generateOutput = async ({ context }: { context: IR.Context }) => {
12+
export const generateOutput = async ({ context }: { context: Context }) => {
1313
const outputPath = path.resolve(context.config.output.path);
1414

1515
if (context.config.output.clean) {

packages/openapi-ts/src/ir/__tests__/pagination.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { describe, expect, it, vi } from 'vitest';
33
import { defaultPaginationKeywords } from '~/config/parser';
44
import type { Config } from '~/types/config';
55

6+
import type { Context } from '../context';
67
import { operationPagination } from '../operation';
78
import { getPaginationKeywordsRegExp } from '../pagination';
89
import type { IR } from '../types';
@@ -92,7 +93,7 @@ describe('operationPagination', () => {
9293
...(pagination ? { pagination: true } : {}),
9394
});
9495

95-
const emptyContext = {} as IR.Context;
96+
const emptyContext = {} as Context;
9697

9798
const baseOperationMeta = {
9899
method: 'post' as const,
@@ -216,7 +217,7 @@ describe('operationPagination', () => {
216217
});
217218

218219
it('resolves $ref and uses the resolved pagination property', () => {
219-
const context: IR.Context = {
220+
const context: Context = {
220221
resolveIrRef: vi.fn().mockReturnValue({
221222
properties: {
222223
pagination: {
@@ -228,7 +229,7 @@ describe('operationPagination', () => {
228229
},
229230
type: 'object',
230231
}),
231-
} as unknown as IR.Context;
232+
} as unknown as Context;
232233

233234
const operation: IR.OperationObject = {
234235
...baseOperationMeta,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Context } from './context';
12
import type { Pagination } from './pagination';
23
import {
34
hasParametersObjectRequired,
@@ -33,7 +34,7 @@ export const operationPagination = ({
3334
context,
3435
operation,
3536
}: {
36-
context: IR.Context;
37+
context: Context;
3738
operation: IR.OperationObject;
3839
}): Pagination | undefined => {
3940
const body = operation.body;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import type { Context } from './context';
12
import type { Pagination } from './pagination';
23
import type { IR } from './types';
34

45
const getPaginationSchema = ({
56
context,
67
parameter,
78
}: {
8-
context: IR.Context;
9+
context: Context;
910
parameter: IR.ParameterObject;
1011
}): IR.SchemaObject | undefined => {
1112
if (!parameter.pagination) {
@@ -66,7 +67,7 @@ export const parameterWithPagination = ({
6667
context,
6768
parameters,
6869
}: {
69-
context: IR.Context;
70+
context: Context;
7071
parameters: IR.ParametersObject | undefined;
7172
}): Pagination | undefined => {
7273
if (!parameters) {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
ServerObject,
55
} from '~/openApi/3.1.x/types/spec';
66

7-
import type { Context as IRContext } from './context';
87
import type { IRMediaType } from './mediaType';
98

109
interface IRBodyObject {
@@ -221,7 +220,6 @@ interface IRModel {
221220
export namespace IR {
222221
export type BodyObject = IRBodyObject;
223222
export type ComponentsObject = IRComponentsObject;
224-
export type Context<Spec extends Record<string, any> = any> = IRContext<Spec>;
225223
export type Model = IRModel;
226224
export type OperationObject = IROperationObject;
227225
export type ParameterObject = IRParameterObject;

packages/openapi-ts/src/openApi/2.0.x/parser/__tests__/operation.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, it } from 'vitest';
22

3-
import type { IR } from '../../../../ir/types';
3+
import type { Context } from '~/ir/context';
4+
45
import type { ParameterObject, SecuritySchemeObject } from '../../types/spec';
56
import { parsePathOperation } from '../operation';
67

@@ -27,7 +28,7 @@ const createContext = () =>
2728
resolveRef: () =>
2829
// Mock implementation
2930
undefined,
30-
}) as unknown as IR.Context;
31+
}) as unknown as Context;
3132

3233
describe('operation', () => {
3334
const context = createContext();

0 commit comments

Comments
 (0)