fork of hey-api/openapi-ts because I need some additional things
1import { StructureModel } from '@hey-api/codegen-core';
2
3import { getTypedConfig } from '../../../../config/utils';
4import { clientFolderAbsolutePath } from '../../../../generate/client';
5import type { $ } from '../../../../py-dsl';
6import { getClientPlugin } from '../../client-core/utils';
7import { resolveStrategy } from '../operations';
8import type { HeyApiSdkPlugin } from '../types';
9import { createShell, type OperationItem, source, toNode } from './node';
10
11export const handlerV1: HeyApiSdkPlugin['Handler'] = ({ plugin }) => {
12 const clientModule = clientFolderAbsolutePath(getTypedConfig(plugin));
13 const client = getClientPlugin(getTypedConfig(plugin));
14 plugin.symbol('Client', {
15 external: clientModule,
16 meta: {
17 category: 'external',
18 resource: 'client.Client',
19 tool: client.name,
20 },
21 });
22
23 const structure = new StructureModel();
24 const shell = createShell(plugin);
25 const strategy = resolveStrategy(plugin);
26
27 plugin.forEach(
28 'operation',
29 (event) => {
30 structure.insert({
31 data: {
32 operation: event.operation,
33 path: event._path,
34 tags: event.tags,
35 } satisfies OperationItem,
36 locations: strategy(event.operation).map((path) => ({ path, shell })),
37 source,
38 });
39 },
40 { order: 'declarations' },
41 );
42
43 const allDependencies: Array<ReturnType<typeof $.class | typeof $.func>> = [];
44 const allNodes: Array<ReturnType<typeof $.class | typeof $.func>> = [];
45
46 for (const node of structure.walk()) {
47 const { dependencies, nodes } = toNode(node, plugin);
48 allDependencies.push(...(dependencies ?? []));
49 allNodes.push(...nodes);
50 }
51
52 for (const dep of allDependencies) {
53 plugin.node(dep);
54 }
55
56 for (const node of allNodes) {
57 plugin.node(node);
58 }
59};