@sdk-it/generic 0.45.0 → 0.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -163
- package/dist/index.js +13 -6
- package/dist/index.js.map +2 -2
- package/dist/lib/generic.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
# @sdk-it/generic
|
|
2
2
|
|
|
3
|
-
<p align="center">
|
|
3
|
+
<p align="center">Analyze TypeScript routes and produce an OpenAPI document</p>
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`@sdk-it/generic` extracts routes, validation schemas, and responses from a
|
|
6
|
+
TypeScript project. Framework packages provide the runtime middleware and
|
|
7
|
+
response analyzer.
|
|
6
8
|
|
|
7
|
-
##
|
|
9
|
+
## Framework integrations
|
|
8
10
|
|
|
9
|
-
- [
|
|
11
|
+
- [Hono](../hono/README.md)
|
|
10
12
|
|
|
11
13
|
## Installation
|
|
12
14
|
|
|
15
|
+
For a Hono project:
|
|
16
|
+
|
|
13
17
|
```bash
|
|
14
|
-
npm install @sdk-it/
|
|
18
|
+
npm install @sdk-it/hono hono zod
|
|
19
|
+
npm install --save-dev @sdk-it/core @sdk-it/generic typescript@^6.0.3
|
|
15
20
|
```
|
|
16
21
|
|
|
17
|
-
##
|
|
18
|
-
|
|
19
|
-
Consider the following example:
|
|
22
|
+
## Analyze a Hono project
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
Define routes with `validate` and an `@openapi` JSDoc tag:
|
|
22
25
|
|
|
23
26
|
```typescript
|
|
24
|
-
|
|
27
|
+
// src/app.ts
|
|
28
|
+
import { Hono } from 'hono';
|
|
29
|
+
import { z } from 'zod';
|
|
25
30
|
|
|
26
|
-
import { validate } from '@sdk-it/
|
|
31
|
+
import { validate } from '@sdk-it/hono/runtime';
|
|
27
32
|
|
|
28
|
-
const app =
|
|
33
|
+
export const app = new Hono();
|
|
29
34
|
|
|
30
35
|
/**
|
|
31
36
|
* @openapi getAuthor
|
|
@@ -35,161 +40,109 @@ app.get(
|
|
|
35
40
|
'/authors/:id',
|
|
36
41
|
validate((payload) => ({
|
|
37
42
|
id: {
|
|
38
|
-
select: payload.
|
|
43
|
+
select: payload.params.id,
|
|
39
44
|
against: z.string(),
|
|
40
45
|
},
|
|
41
46
|
})),
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
return
|
|
47
|
+
(c) => {
|
|
48
|
+
const { id } = c.var.input;
|
|
49
|
+
return c.json({ id, name: 'John Doe' });
|
|
45
50
|
},
|
|
46
51
|
);
|
|
47
52
|
```
|
|
48
53
|
|
|
49
|
-
|
|
54
|
+
Analyze the TypeScript project and write the resulting OpenAPI document:
|
|
50
55
|
|
|
51
56
|
```typescript
|
|
52
|
-
|
|
57
|
+
// openapi.ts
|
|
58
|
+
import { writeFile } from 'node:fs/promises';
|
|
53
59
|
|
|
54
|
-
import { analyze
|
|
55
|
-
import {
|
|
60
|
+
import { analyze } from '@sdk-it/generic';
|
|
61
|
+
import { responseAnalyzer } from '@sdk-it/hono';
|
|
56
62
|
|
|
57
|
-
const { paths, components } = await analyze('
|
|
63
|
+
const { paths, components, tags } = await analyze('./tsconfig.json', {
|
|
58
64
|
responseAnalyzer,
|
|
59
65
|
});
|
|
60
66
|
|
|
61
67
|
const spec = {
|
|
68
|
+
openapi: '3.1.0',
|
|
62
69
|
info: {
|
|
63
70
|
title: 'My API',
|
|
64
71
|
version: '1.0.0',
|
|
65
72
|
},
|
|
66
73
|
paths,
|
|
67
74
|
components,
|
|
75
|
+
tags: tags.map((name) => ({ name })),
|
|
68
76
|
};
|
|
69
77
|
|
|
70
|
-
await writeFile(
|
|
71
|
-
join(process.cwd(), 'openapi.json'),
|
|
72
|
-
JSON.stringify(spec, null, 2),
|
|
73
|
-
);
|
|
78
|
+
await writeFile('openapi.json', JSON.stringify(spec, null, 2));
|
|
74
79
|
```
|
|
75
80
|
|
|
76
|
-
|
|
77
|
-
> See [typescript](../typescript/README.md) to create fully functional SDKs from the generated OpenAPI specification.
|
|
81
|
+
Run the script with Node.js 24 or newer:
|
|
78
82
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
**Use file name as tag**
|
|
83
|
+
```bash
|
|
84
|
+
node openapi.ts
|
|
85
|
+
```
|
|
84
86
|
|
|
85
|
-
|
|
87
|
+
See [`@sdk-it/typescript`](../typescript/README.md) to generate a client from
|
|
88
|
+
the OpenAPI document.
|
|
86
89
|
|
|
87
|
-
|
|
88
|
-
apps/
|
|
89
|
-
backend/
|
|
90
|
-
tsconfig.app.json
|
|
91
|
-
src/
|
|
92
|
-
routes/
|
|
93
|
-
authors.ts
|
|
94
|
-
```
|
|
90
|
+
## Customize operations
|
|
95
91
|
|
|
96
|
-
|
|
92
|
+
`onOperation` receives every derived operation. This example uses the route
|
|
93
|
+
file name as its tag:
|
|
97
94
|
|
|
98
95
|
```typescript
|
|
99
96
|
import { basename } from 'node:path';
|
|
100
|
-
import { camelcase } from 'stringcase';
|
|
101
97
|
|
|
102
|
-
import { analyze
|
|
98
|
+
import { analyze } from '@sdk-it/generic';
|
|
99
|
+
import { responseAnalyzer } from '@sdk-it/hono';
|
|
103
100
|
|
|
104
|
-
const { paths, components } = await analyze(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
[
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
tags: [fileName],
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
};
|
|
101
|
+
const { paths, components } = await analyze(
|
|
102
|
+
'./apps/backend/tsconfig.app.json',
|
|
103
|
+
{
|
|
104
|
+
responseAnalyzer,
|
|
105
|
+
onOperation(sourceFile, _method, _path, operation) {
|
|
106
|
+
operation.tags = [basename(sourceFile, '.ts')];
|
|
107
|
+
return {};
|
|
108
|
+
},
|
|
116
109
|
},
|
|
117
|
-
|
|
110
|
+
);
|
|
118
111
|
```
|
|
119
112
|
|
|
120
|
-
|
|
113
|
+
## Customize type mappings
|
|
121
114
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
115
|
+
Use `typesMap` for TypeScript types without a direct OpenAPI representation.
|
|
116
|
+
For example, map Prisma's `Decimal` to a string so it keeps its precision on
|
|
117
|
+
the wire:
|
|
125
118
|
|
|
126
119
|
```typescript
|
|
127
|
-
import { writeFile } from 'node:fs/promises';
|
|
128
|
-
import { join } from 'node:path';
|
|
129
|
-
import { cwd } from 'node:process';
|
|
130
|
-
|
|
131
120
|
import { defaultTypesMap } from '@sdk-it/core';
|
|
132
121
|
import { analyze } from '@sdk-it/generic';
|
|
133
122
|
import { responseAnalyzer } from '@sdk-it/hono';
|
|
134
123
|
|
|
135
|
-
|
|
136
|
-
const customTypeMappings = {
|
|
137
|
-
Decimal: 'string',
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const { paths, components } = await analyze('path/to/tsconfig.json', {
|
|
124
|
+
const { paths, components } = await analyze('./tsconfig.json', {
|
|
141
125
|
responseAnalyzer,
|
|
142
126
|
typesMap: {
|
|
143
127
|
...defaultTypesMap,
|
|
144
128
|
Decimal: 'string',
|
|
145
129
|
},
|
|
146
130
|
});
|
|
147
|
-
|
|
148
|
-
const spec = {
|
|
149
|
-
openapi: '3.1.0',
|
|
150
|
-
info: {
|
|
151
|
-
title: 'My API',
|
|
152
|
-
version: '1.0.0',
|
|
153
|
-
},
|
|
154
|
-
paths,
|
|
155
|
-
components,
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
await writeFile('openapi.json', JSON.stringify(spec, null, 2));
|
|
159
131
|
```
|
|
160
132
|
|
|
161
|
-
|
|
133
|
+
## Reference external schemas
|
|
162
134
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
By default, the analyzer only sees schemas defined inline in the validate middleware.
|
|
166
|
-
|
|
167
|
-
For instance the following route handler is perfectly valid and will be analyzed correctly.
|
|
135
|
+
The analyzer can evaluate inline Zod schemas directly:
|
|
168
136
|
|
|
169
137
|
```typescript
|
|
170
|
-
|
|
171
|
-
* @openapi getAuthor
|
|
172
|
-
* @tags authors
|
|
173
|
-
*/
|
|
174
|
-
app.get(
|
|
175
|
-
'/authors/:id',
|
|
176
|
-
validate((payload) => ({
|
|
177
|
-
id: {
|
|
178
|
-
select: payload.param.id,
|
|
179
|
-
against: z.string(),
|
|
180
|
-
},
|
|
181
|
-
})),
|
|
182
|
-
async (req, res) => {
|
|
183
|
-
const { id } = req.input;
|
|
184
|
-
return res.json({ id, name: 'John Doe' });
|
|
185
|
-
},
|
|
186
|
-
);
|
|
138
|
+
against: z.string().min(2).max(100);
|
|
187
139
|
```
|
|
188
140
|
|
|
189
|
-
|
|
141
|
+
When a validator references a schema from another file, use a namespace import
|
|
142
|
+
in the route:
|
|
190
143
|
|
|
191
|
-
```
|
|
192
|
-
//
|
|
144
|
+
```typescript
|
|
145
|
+
// src/schemas.ts
|
|
193
146
|
import { z } from 'zod';
|
|
194
147
|
|
|
195
148
|
export const authorSchema = z.object({
|
|
@@ -198,88 +151,62 @@ export const authorSchema = z.object({
|
|
|
198
151
|
});
|
|
199
152
|
```
|
|
200
153
|
|
|
201
|
-
```
|
|
154
|
+
```typescript
|
|
155
|
+
// src/app.ts
|
|
156
|
+
import { Hono } from 'hono';
|
|
202
157
|
import crypto from 'node:crypto';
|
|
203
158
|
import { z } from 'zod';
|
|
204
159
|
|
|
205
|
-
import { validate } from '@sdk-it/
|
|
160
|
+
import { validate } from '@sdk-it/hono/runtime';
|
|
206
161
|
|
|
207
|
-
import
|
|
162
|
+
import * as schemas from './schemas.ts';
|
|
163
|
+
|
|
164
|
+
const app = new Hono();
|
|
208
165
|
|
|
209
|
-
/**
|
|
210
|
-
* @openapi createBook
|
|
211
|
-
* @tags books
|
|
212
|
-
*/
|
|
213
166
|
app.post(
|
|
214
167
|
'/books',
|
|
215
|
-
validate((payload) => ({
|
|
168
|
+
validate('application/json', (payload) => ({
|
|
216
169
|
title: {
|
|
217
170
|
select: payload.body.title,
|
|
218
171
|
against: z.string().min(2).max(100),
|
|
219
172
|
},
|
|
220
173
|
author: {
|
|
221
174
|
select: payload.body.author,
|
|
222
|
-
against: authorSchema,
|
|
175
|
+
against: schemas.authorSchema,
|
|
223
176
|
},
|
|
224
177
|
})),
|
|
225
|
-
|
|
226
|
-
const { title, author } =
|
|
227
|
-
return
|
|
178
|
+
(c) => {
|
|
179
|
+
const { title, author } = c.var.input;
|
|
180
|
+
return c.json({ id: crypto.randomUUID(), title, author }, 201);
|
|
228
181
|
},
|
|
229
182
|
);
|
|
230
183
|
```
|
|
231
184
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
The analyzer's `imports` option lets you include additional files in the analysis.
|
|
185
|
+
Then inject that namespace when analyzing the project:
|
|
235
186
|
|
|
236
|
-
```
|
|
237
|
-
import {
|
|
187
|
+
```typescript
|
|
188
|
+
import { fileURLToPath } from 'node:url';
|
|
238
189
|
|
|
239
190
|
import { analyze } from '@sdk-it/generic';
|
|
191
|
+
import { responseAnalyzer } from '@sdk-it/hono';
|
|
240
192
|
|
|
241
|
-
const { paths, components } = await analyze('
|
|
193
|
+
const { paths, components } = await analyze('./tsconfig.json', {
|
|
242
194
|
responseAnalyzer,
|
|
243
195
|
imports: [
|
|
244
196
|
{
|
|
245
197
|
import: 'schemas',
|
|
246
|
-
from:
|
|
198
|
+
from: fileURLToPath(new URL('./src/schemas.ts', import.meta.url)),
|
|
247
199
|
},
|
|
248
200
|
],
|
|
249
201
|
});
|
|
250
202
|
```
|
|
251
203
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
```ts
|
|
255
|
-
import * as schemas from './schemas';
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* @openapi createBook
|
|
259
|
-
* @tags books
|
|
260
|
-
*/
|
|
261
|
-
app.post(
|
|
262
|
-
'/books',
|
|
263
|
-
validate((payload) => ({
|
|
264
|
-
title: {
|
|
265
|
-
select: payload.body.title,
|
|
266
|
-
against: z.string().min(2).max(100),
|
|
267
|
-
},
|
|
268
|
-
author: {
|
|
269
|
-
select: payload.body.author,
|
|
270
|
-
against: schemas.authorSchema,
|
|
271
|
-
},
|
|
272
|
-
})),
|
|
273
|
-
async (req, res) => {
|
|
274
|
-
const { title, author } = req.input;
|
|
275
|
-
return res.json({ id: crypto.randomUUID(), title, author });
|
|
276
|
-
},
|
|
277
|
-
);
|
|
278
|
-
```
|
|
204
|
+
The injected file must be loadable by the Node.js process running the
|
|
205
|
+
analyzer.
|
|
279
206
|
|
|
280
|
-
|
|
207
|
+
## Hide an operation
|
|
281
208
|
|
|
282
|
-
|
|
209
|
+
Add `@access private` to exclude a route from the generated OpenAPI document:
|
|
283
210
|
|
|
284
211
|
```typescript
|
|
285
212
|
/**
|
|
@@ -287,10 +214,14 @@ Control endpoint visibility with the `@access` tag in JSDoc comments. For now, o
|
|
|
287
214
|
* @tags authors
|
|
288
215
|
* @access private
|
|
289
216
|
*/
|
|
290
|
-
app.get(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
217
|
+
app.get(
|
|
218
|
+
'/authors/:id',
|
|
219
|
+
validate((payload) => ({
|
|
220
|
+
id: {
|
|
221
|
+
select: payload.params.id,
|
|
222
|
+
against: z.string(),
|
|
223
|
+
},
|
|
224
|
+
})),
|
|
225
|
+
(c) => c.json({ id: c.var.input.id, name: 'John Doe' }),
|
|
226
|
+
);
|
|
294
227
|
```
|
|
295
|
-
|
|
296
|
-
In this example, the `getAuthor` operation will be hidden from the generated OpenAPI specification.
|
package/dist/index.js
CHANGED
|
@@ -5,10 +5,10 @@ import ts from "typescript";
|
|
|
5
5
|
import {
|
|
6
6
|
Paths,
|
|
7
7
|
TypeDeriver,
|
|
8
|
-
nodeLocation,
|
|
9
8
|
getProgram,
|
|
10
9
|
isCallExpression,
|
|
11
10
|
isHttpMethod,
|
|
11
|
+
nodeLocation,
|
|
12
12
|
toSchema
|
|
13
13
|
} from "@sdk-it/core";
|
|
14
14
|
function symbolFile(symbol) {
|
|
@@ -226,7 +226,10 @@ function visit(node, responseAnalyzer2, paths, typeChecker, typeDeriver) {
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
if (declaration) {
|
|
229
|
-
middlewareDeclarations.push({
|
|
229
|
+
middlewareDeclarations.push({
|
|
230
|
+
node: declaration,
|
|
231
|
+
name: middlewareFnName
|
|
232
|
+
});
|
|
230
233
|
}
|
|
231
234
|
}
|
|
232
235
|
if (ts.isIdentifier(arg.expression) && arg.expression.text === "validate") {
|
|
@@ -287,14 +290,18 @@ function toSelectors(props) {
|
|
|
287
290
|
const name = prop.name.getText();
|
|
288
291
|
const select = prop.initializer.properties.filter(ts.isPropertyAssignment).find((prop2) => prop2.name.getText() === "select");
|
|
289
292
|
if (!select) {
|
|
290
|
-
console.warn(
|
|
291
|
-
|
|
293
|
+
console.warn(
|
|
294
|
+
`\u26A0 No select found in ${name}
|
|
295
|
+
at ${nodeLocation(prop) ?? "unknown"}`
|
|
296
|
+
);
|
|
292
297
|
continue;
|
|
293
298
|
}
|
|
294
299
|
const against = prop.initializer.properties.filter(ts.isPropertyAssignment).find((prop2) => prop2.name.getText() === "against");
|
|
295
300
|
if (!against) {
|
|
296
|
-
console.warn(
|
|
297
|
-
|
|
301
|
+
console.warn(
|
|
302
|
+
`\u26A0 No against found in ${name}
|
|
303
|
+
at ${nodeLocation(prop) ?? "unknown"}`
|
|
304
|
+
);
|
|
298
305
|
continue;
|
|
299
306
|
}
|
|
300
307
|
const [, source, selectText] = select.initializer.getText().split(".");
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/lib/generic.ts", "../src/lib/response-analyzer.ts"],
|
|
4
|
-
"sourcesContent": ["import debug from 'debug';\nimport type { ComponentsObject } from 'openapi3-ts/oas31';\nimport { camelcase } from 'stringcase';\nimport ts from 'typescript';\n\nimport {\n type InjectImport,\n type NaunceResponseAnalyzer,\n type OnOperation,\n Paths,\n type ResponseAnalyzerFn,\n type ResponseItem,\n type Selector,\n type SemanticSource,\n TypeDeriver,\n nodeLocation,\n getProgram,\n isCallExpression,\n isHttpMethod,\n toSchema,\n} from '@sdk-it/core';\n\n/**\n * Gets the file path from a symbol's first declaration\n */\nfunction symbolFile(symbol: ts.Symbol | undefined): string | undefined {\n if (!symbol) {\n return undefined;\n }\n\n const declarations = symbol.declarations ?? [];\n if (declarations.length === 0) {\n return undefined;\n }\n\n const sourceFile = declarations[0].getSourceFile();\n return sourceFile?.fileName;\n}\n\n/**\n * Determines if a symbol is from an external library (node_modules)\n */\nfunction isExternalFunction(symbol: ts.Symbol | undefined): boolean {\n const fileName = symbolFile(symbol);\n return fileName ? fileName.includes('node_modules') : false;\n}\n\n/**\n * Determines if a symbol refers to a local function (not from node_modules)\n */\nfunction isLocalFunction(symbol: ts.Symbol | undefined): boolean {\n if (!symbol) {\n return false;\n }\n\n return !isExternalFunction(symbol);\n}\n\nexport const returnTokens = (\n node: ts.Node,\n typeChecker?: ts.TypeChecker,\n options?: { consider3rdParty?: boolean; maxDepth?: number },\n) => {\n const tokens: { token: string; node: ts.Expression }[] = [];\n const consider3rdParty = options?.consider3rdParty ?? false;\n const maxDepth = options?.maxDepth ?? 5;\n // Track visited function declarations to prevent infinite recursion\n const visitedFunctions = new Set<ts.Declaration>();\n\n const visitor = (node: ts.Node, depth: number): void => {\n // Skip if we've exceeded max depth\n if (depth > maxDepth) {\n return;\n }\n\n if (ts.isThrowStatement(node)) {\n if (ts.isNewExpression(node.expression)) {\n tokens.push({\n token: `throw.new.${node.expression.expression.getText()}`,\n node: node.expression,\n });\n }\n }\n\n if (ts.isReturnStatement(node) && node.expression) {\n if (ts.isCallExpression(node.expression)) {\n tokens.push({\n token: node.expression.expression.getText(),\n node: node.expression,\n });\n }\n if (ts.isNewExpression(node.expression)) {\n tokens.push({\n token: `new.${node.expression.expression.getText()}`,\n node: node.expression,\n });\n }\n // Continue traversing into the returned expression (e.g., arrow functions)\n // This handles: return async (c, next) => { throw ... }\n ts.forEachChild(node.expression, (child) => visitor(child, depth));\n return;\n }\n\n // If we encounter a call expression and have a type checker, follow it\n if (ts.isCallExpression(node) && typeChecker && depth < maxDepth) {\n const callExpression = node;\n\n // Try to resolve the function being called\n let symbol: ts.Symbol | undefined;\n\n if (ts.isIdentifier(callExpression.expression)) {\n symbol = typeChecker.getSymbolAtLocation(callExpression.expression);\n } else if (ts.isPropertyAccessExpression(callExpression.expression)) {\n symbol = typeChecker.getSymbolAtLocation(\n callExpression.expression.name,\n );\n }\n\n // Resolve aliases\n if (symbol && symbol.flags & ts.SymbolFlags.Alias) {\n symbol = typeChecker.getAliasedSymbol(symbol);\n }\n\n // Check if we should follow this function\n const shouldFollow = consider3rdParty || isLocalFunction(symbol);\n\n if (shouldFollow && symbol) {\n const declarations = symbol?.declarations ?? [];\n\n for (const declaration of declarations) {\n // Skip if we've already visited this function (prevent infinite recursion)\n if (visitedFunctions.has(declaration)) {\n continue;\n }\n\n if (isFunctionWithBody(declaration) && declaration.body) {\n visitedFunctions.add(declaration);\n // Recursively visit the function body with incremented depth\n visitor(declaration.body, depth + 1);\n }\n }\n }\n }\n\n ts.forEachChild(node, (child) => visitor(child, depth));\n };\n\n visitor(node, 0);\n return tokens;\n};\n\nconst logger = debug('@sdk-it/generic');\n\nconst jsDocsTags = [\n 'openapi',\n 'tags',\n 'description',\n 'summary',\n 'access',\n 'tool',\n 'toolDescription',\n] as const;\ntype JSDocsTags = (typeof jsDocsTags)[number];\n\nfunction parseJSDocComment(node: ts.Node) {\n let tags: string[] = [];\n let name = '';\n let description = '';\n let summary = '';\n let access = '';\n let tool = '';\n let toolDescription = '';\n\n for (const tag of ts.getAllJSDocTags(node, (tag): tag is ts.JSDocTag =>\n jsDocsTags.includes(tag.tagName.text as JSDocsTags),\n )) {\n if (typeof tag.comment !== 'string') {\n continue;\n }\n switch (tag.tagName.text as JSDocsTags) {\n case 'openapi':\n name = tag.comment;\n break;\n case 'tags':\n tags = tag.comment.split(',').map((tag) => tag.trim());\n break;\n case 'description':\n description = tag.comment;\n break;\n case 'summary':\n summary = tag.comment;\n break;\n case 'access':\n access = tag.comment.trim().toLowerCase();\n break;\n case 'tool':\n tool = tag.comment.trim();\n break;\n case 'toolDescription':\n toolDescription = tag.comment.trim();\n break;\n }\n }\n return {\n name,\n tags,\n description,\n access,\n tool,\n toolDescription,\n summary,\n };\n}\n\nfunction visit(\n node: ts.Node,\n responseAnalyzer: (\n handler: ts.ArrowFunction | ts.FunctionExpression,\n token: string,\n node: ts.Node,\n ) => ResponseItem[],\n paths: Paths,\n typeChecker: ts.TypeChecker,\n typeDeriver: TypeDeriver,\n) {\n if (!ts.isCallExpression(node) || node.arguments.length < 2) {\n return moveOn();\n }\n if (\n !ts.isPropertyAccessExpression(node.expression) ||\n !ts.isIdentifier(node.expression.name) ||\n !isHttpMethod(node.expression.name.text)\n ) {\n return moveOn();\n }\n\n const [pathNode] = node.arguments;\n if (!ts.isStringLiteral(pathNode)) {\n return moveOn();\n }\n const method = node.expression.name.text;\n const path = pathNode.text;\n const validate = node.arguments.find((arg) =>\n isCallExpression(arg, 'validate'),\n );\n if (!validate) {\n return moveOn();\n }\n const handler = node.arguments.at(-1);\n if (!handler || !ts.isArrowFunction(handler)) {\n return moveOn();\n }\n const metadata = parseJSDocComment(node.parent);\n // Skip endpoints marked as private access\n if (metadata.access === 'private') {\n return moveOn();\n }\n const operationName =\n metadata.name ||\n camelcase(`${method} ${path.replace(/[^a-zA-Z0-9]/g, '')}`);\n if (!validate.arguments.length) {\n return moveOn();\n }\n\n let selector: ts.Expression | undefined;\n let contentType: ts.Expression | undefined;\n if (validate.arguments.length === 2) {\n contentType = validate.arguments[0];\n selector = validate.arguments[1];\n } else {\n selector = validate.arguments[0];\n }\n if (!ts.isArrowFunction(selector)) {\n return moveOn();\n }\n if (\n !selector ||\n !ts.isParenthesizedExpression(selector.body) ||\n !ts.isObjectLiteralExpression(selector.body.expression)\n ) {\n return moveOn();\n }\n\n // Collect all middleware declarations for analysis\n const middlewareDeclarations: { node: ts.Node; name?: string }[] = [];\n\n // slice(1, -1) to skip first (path) and last (handler) arguments\n // and skip the validate middleware - it's handled separately\n for (const arg of node.arguments.slice(1, -1)) {\n if (ts.isCallExpression(arg)) {\n // Try to resolve the factory function declaration\n if (ts.isIdentifier(arg.expression)) {\n const middlewareFnName = arg.expression.text;\n let symbol = typeChecker.getSymbolAtLocation(arg.expression);\n\n // If symbol has alias, resolve to the actual symbol\n if (symbol && symbol.flags & ts.SymbolFlags.Alias) {\n symbol = typeChecker.getAliasedSymbol(symbol);\n }\n\n const allDeclarations = [\n symbol?.valueDeclaration,\n ...(symbol?.declarations ?? []),\n ].filter((it) => !!it);\n\n let declaration = allDeclarations.find(isFunctionWithBody);\n\n // If not found, check for variable declarations with function initializers\n if (!declaration) {\n for (const decl of allDeclarations) {\n if (ts.isVariableDeclaration(decl) && decl.initializer) {\n if (isFunctionWithBody(decl.initializer)) {\n declaration = decl.initializer;\n break;\n }\n }\n }\n }\n\n if (declaration) {\n middlewareDeclarations.push({ node: declaration, name: middlewareFnName });\n }\n }\n\n // Also check if the call expression argument itself is an arrow function\n // e.g., middleware((ctx) => {...})\n // But skip if the function name is 'validate'\n if (\n ts.isIdentifier(arg.expression) &&\n arg.expression.text === 'validate'\n ) {\n continue;\n }\n const firstArg = arg.arguments[0];\n if (isFunctionWithBody(firstArg)) {\n middlewareDeclarations.push({ node: firstArg });\n }\n }\n }\n\n const props = selector.body.expression.properties.filter(\n ts.isPropertyAssignment,\n );\n\n const sourceFile = node.getSourceFile();\n\n typeDeriver.setTrace({\n file: sourceFile.fileName,\n operation: `${method.toUpperCase()} ${path}`,\n });\n\n const responses: ResponseItem[] = [];\n\n // Analyze all middlewares for potential responses\n for (const middleware of middlewareDeclarations) {\n for (const { token, node } of returnTokens(middleware.node, typeChecker)) {\n const items = responseAnalyzer(middleware.node as any, token, node);\n if (middleware.name) {\n for (const item of items) {\n item.middlewareName = middleware.name;\n }\n }\n responses.push(...items);\n }\n }\n\n // Analyze the main handler for responses\n for (const { token, node } of returnTokens(handler, typeChecker)) {\n responses.push(...responseAnalyzer(handler, token, node));\n }\n\n paths.addPath(\n operationName,\n path,\n method,\n contentType\n ? ts.isStringLiteral(contentType)\n ? contentType.text\n : undefined\n : undefined,\n toSelectors(props),\n responses,\n sourceFile.fileName,\n metadata,\n );\n\n function moveOn() {\n ts.forEachChild(node, (node) =>\n visit(node, responseAnalyzer, paths, typeChecker, typeDeriver),\n );\n }\n}\n\nfunction toSelectors(props: ts.PropertyAssignment[]) {\n const selectors: Selector[] = [];\n for (const prop of props) {\n if (!ts.isObjectLiteralExpression(prop.initializer)) {\n continue;\n }\n const name = prop.name.getText();\n const select = prop.initializer.properties\n .filter(ts.isPropertyAssignment)\n .find((prop) => prop.name.getText() === 'select');\n if (!select) {\n console.warn(`\\u26a0 No select found in ${name}\\n at ${nodeLocation(prop) ?? 'unknown'}`);\n continue;\n }\n const against = prop.initializer.properties\n .filter(ts.isPropertyAssignment)\n .find((prop) => prop.name.getText() === 'against');\n if (!against) {\n console.warn(`\\u26a0 No against found in ${name}\\n at ${nodeLocation(prop) ?? 'unknown'}`);\n continue;\n }\n const [, source, selectText] = select.initializer.getText().split('.');\n selectors.push({\n name: selectText,\n against: against.initializer.getText(),\n source: source as SemanticSource,\n });\n }\n return selectors;\n}\n\nexport async function analyze(\n tsconfigPath: string,\n config: {\n /**\n * Additional code to inject before resolving zod schemas\n */\n imports?: InjectImport[];\n typesMap?: Record<string, string>;\n responseAnalyzer: ResponseAnalyzerFn | NaunceResponseAnalyzer;\n onOperation?: OnOperation;\n },\n) {\n logger(`Parsing tsconfig`);\n const program = getProgram(tsconfigPath);\n logger(`Program created`);\n const typeChecker = program.getTypeChecker();\n\n logger(`Type checker created`);\n const typeDeriver = new TypeDeriver(typeChecker, config.typesMap);\n const paths = new Paths({\n imports: config.imports ?? [],\n onOperation: config.onOperation,\n });\n\n for (const sourceFile of program.getSourceFiles()) {\n logger(`Analyzing ${sourceFile.fileName}`);\n if (!sourceFile.isDeclarationFile) {\n logger(`Visiting ${sourceFile.fileName}`);\n visit(\n sourceFile,\n (handler, token, node) => {\n const responseAnalyzer = config.responseAnalyzer;\n if (typeof responseAnalyzer !== 'function') {\n const naunce =\n responseAnalyzer[token] || responseAnalyzer['default'];\n if (!naunce) {\n throw new Error(`No response analyzer for token ${token}`);\n }\n return naunce(handler, typeDeriver, node);\n }\n return responseAnalyzer(handler, typeDeriver);\n },\n paths,\n typeChecker,\n typeDeriver,\n );\n }\n }\n\n const components: ComponentsObject = {\n schemas: {\n ...paths.getSharedSchemas(),\n ...Object.entries(typeDeriver.collector).reduce(\n (acc, [key, value]) => ({ ...acc, [key]: toSchema(value) }),\n {},\n ),\n },\n };\n\n return {\n paths: await paths.getPaths(),\n tags: paths.getTags(),\n components,\n };\n}\n\nexport type Serialized = ReturnType<typeof analyze>;\n\nfunction isFunctionWithBody(\n node: ts.Node | ts.Declaration | undefined,\n): node is ts.FunctionLikeDeclaration & { body: ts.Block | ts.Expression } {\n if (!node) {\n return false;\n }\n return (\n (ts.isFunctionDeclaration(node) ||\n ts.isFunctionExpression(node) ||\n ts.isArrowFunction(node) ||\n ts.isMethodDeclaration(node) ||\n ts.isConstructorDeclaration(node) ||\n ts.isGetAccessor(node) ||\n ts.isSetAccessor(node)) &&\n !!node.body\n );\n}\n", "import ts from 'typescript';\n\nimport type {\n NaunceResponseAnalyzer,\n ResponseItem,\n TypeDeriver,\n} from '@sdk-it/core';\n\nconst handlerVisitor: (\n on: (\n node: ts.Node | undefined,\n statusCode: ts.Node | undefined,\n headers: ts.Node | undefined,\n contentType: string,\n ) => void,\n) => ts.Visitor = (callback) => {\n return (node: ts.Node) => {\n if (ts.isReturnStatement(node) && node.expression) {\n if (\n ts.isCallExpression(node.expression) &&\n ts.isPropertyAccessExpression(node.expression.expression)\n ) {\n const propAccess = node.expression.expression;\n if (\n ts.isIdentifier(propAccess.expression) &&\n propAccess.expression.text === 'output'\n ) {\n let contentType = 'application/json';\n const callerMethod = propAccess.name.text;\n const [body, statusCode, headers] = node.expression.arguments;\n if (callerMethod === 'attachment') {\n contentType = 'application/octet-stream';\n }\n if (!body) {\n contentType = 'empty';\n }\n callback(body, statusCode, headers, contentType);\n }\n }\n }\n return ts.forEachChild(node, handlerVisitor(callback));\n };\n};\n\nfunction toResponses(\n handler: ts.ArrowFunction | ts.FunctionExpression,\n deriver: TypeDeriver,\n) {\n const responsesList: ResponseItem[] = [];\n const visit = handlerVisitor((node, statusCode, headers, contentType) => {\n responsesList.push({\n headers: headers ? Object.keys(deriver.serializeNode(headers)) : [],\n contentType,\n statusCode: statusCode ? resolveStatusCode(statusCode) : '200',\n response: node ? deriver.serializeNode(node) : undefined,\n });\n });\n visit(handler.body);\n return responsesList;\n}\n\nfunction resolveStatusCode(node: ts.Node) {\n if (ts.isNumericLiteral(node)) {\n return node.text;\n }\n throw new Error(`Could not resolve status code`);\n}\n\nexport function defaultResponseAnalyzer(\n handler: ts.ArrowFunction | ts.FunctionExpression,\n deriver: TypeDeriver,\n) {\n try {\n return toResponses(handler, deriver);\n } catch (error) {\n console.error('Error analyzing response\\n', handler.getText());\n throw error;\n }\n}\n\nexport const responseAnalyzer: NaunceResponseAnalyzer = {\n 'throw.new.ProblemDetailsException': (handler, deriver, node) => {\n if (ts.isNewExpression(node)) {\n const [problem] = node.arguments ?? [];\n if (!ts.isObjectLiteralExpression(problem)) {\n return [];\n }\n const properties = problem.properties.reduce<Record<string, string>>(\n (acc, prop) => {\n if (ts.isPropertyAssignment(prop)) {\n const key = prop.name.getText();\n if (ts.isLiteralExpression(prop.initializer)) {\n acc[key] = prop.initializer.text;\n } else {\n acc[key] = prop.initializer.getText();\n }\n }\n return acc;\n },\n {},\n );\n return [\n {\n contentType: 'application/problem+json',\n headers: [],\n statusCode: properties.status,\n response: deriver.serializeNode(problem),\n },\n ];\n }\n return [];\n },\n default: defaultResponseAnalyzer,\n};\n\nexport default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AG;AAC7C,QAAI,GAAG,iBAAiB,GAAG,GAAG;AAE5B,UAAI,GAAG,aAAa,IAAI,UAAU,GAAG;AACnC,cAAM,mBAAmB,IAAI,WAAW;AACxC,YAAI,SAAS,YAAY,oBAAoB,IAAI,UAAU;AAG3D,YAAI,UAAU,OAAO,QAAQ,GAAG,YAAY,OAAO;AACjD,mBAAS,YAAY,iBAAiB,MAAM;AAAA,QAC9C;AAEA,cAAM,kBAAkB;AAAA,UACtB,QAAQ;AAAA,UACR,GAAI,QAAQ,gBAAgB,CAAC;AAAA,QAC/B,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE;AAErB,YAAI,cAAc,gBAAgB,KAAK,kBAAkB;AAGzD,YAAI,CAAC,aAAa;AAChB,qBAAW,QAAQ,iBAAiB;AAClC,gBAAI,GAAG,sBAAsB,IAAI,KAAK,KAAK,aAAa;AACtD,kBAAI,mBAAmB,KAAK,WAAW,GAAG;AACxC,8BAAc,KAAK;AACnB;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAEA,YAAI,aAAa;AACf,iCAAuB,KAAK,
|
|
4
|
+
"sourcesContent": ["import debug from 'debug';\nimport type { ComponentsObject } from 'openapi3-ts/oas31';\nimport { camelcase } from 'stringcase';\nimport ts from 'typescript';\n\nimport {\n type InjectImport,\n type NaunceResponseAnalyzer,\n type OnOperation,\n Paths,\n type ResponseAnalyzerFn,\n type ResponseItem,\n type Selector,\n type SemanticSource,\n TypeDeriver,\n getProgram,\n isCallExpression,\n isHttpMethod,\n nodeLocation,\n toSchema,\n} from '@sdk-it/core';\n\n/**\n * Gets the file path from a symbol's first declaration\n */\nfunction symbolFile(symbol: ts.Symbol | undefined): string | undefined {\n if (!symbol) {\n return undefined;\n }\n\n const declarations = symbol.declarations ?? [];\n if (declarations.length === 0) {\n return undefined;\n }\n\n const sourceFile = declarations[0].getSourceFile();\n return sourceFile?.fileName;\n}\n\n/**\n * Determines if a symbol is from an external library (node_modules)\n */\nfunction isExternalFunction(symbol: ts.Symbol | undefined): boolean {\n const fileName = symbolFile(symbol);\n return fileName ? fileName.includes('node_modules') : false;\n}\n\n/**\n * Determines if a symbol refers to a local function (not from node_modules)\n */\nfunction isLocalFunction(symbol: ts.Symbol | undefined): boolean {\n if (!symbol) {\n return false;\n }\n\n return !isExternalFunction(symbol);\n}\n\nexport const returnTokens = (\n node: ts.Node,\n typeChecker?: ts.TypeChecker,\n options?: { consider3rdParty?: boolean; maxDepth?: number },\n) => {\n const tokens: { token: string; node: ts.Expression }[] = [];\n const consider3rdParty = options?.consider3rdParty ?? false;\n const maxDepth = options?.maxDepth ?? 5;\n // Track visited function declarations to prevent infinite recursion\n const visitedFunctions = new Set<ts.Declaration>();\n\n const visitor = (node: ts.Node, depth: number): void => {\n // Skip if we've exceeded max depth\n if (depth > maxDepth) {\n return;\n }\n\n if (ts.isThrowStatement(node)) {\n if (ts.isNewExpression(node.expression)) {\n tokens.push({\n token: `throw.new.${node.expression.expression.getText()}`,\n node: node.expression,\n });\n }\n }\n\n if (ts.isReturnStatement(node) && node.expression) {\n if (ts.isCallExpression(node.expression)) {\n tokens.push({\n token: node.expression.expression.getText(),\n node: node.expression,\n });\n }\n if (ts.isNewExpression(node.expression)) {\n tokens.push({\n token: `new.${node.expression.expression.getText()}`,\n node: node.expression,\n });\n }\n // Continue traversing into the returned expression (e.g., arrow functions)\n // This handles: return async (c, next) => { throw ... }\n ts.forEachChild(node.expression, (child) => visitor(child, depth));\n return;\n }\n\n // If we encounter a call expression and have a type checker, follow it\n if (ts.isCallExpression(node) && typeChecker && depth < maxDepth) {\n const callExpression = node;\n\n // Try to resolve the function being called\n let symbol: ts.Symbol | undefined;\n\n if (ts.isIdentifier(callExpression.expression)) {\n symbol = typeChecker.getSymbolAtLocation(callExpression.expression);\n } else if (ts.isPropertyAccessExpression(callExpression.expression)) {\n symbol = typeChecker.getSymbolAtLocation(\n callExpression.expression.name,\n );\n }\n\n // Resolve aliases\n if (symbol && symbol.flags & ts.SymbolFlags.Alias) {\n symbol = typeChecker.getAliasedSymbol(symbol);\n }\n\n // Check if we should follow this function\n const shouldFollow = consider3rdParty || isLocalFunction(symbol);\n\n if (shouldFollow && symbol) {\n const declarations = symbol?.declarations ?? [];\n\n for (const declaration of declarations) {\n // Skip if we've already visited this function (prevent infinite recursion)\n if (visitedFunctions.has(declaration)) {\n continue;\n }\n\n if (isFunctionWithBody(declaration) && declaration.body) {\n visitedFunctions.add(declaration);\n // Recursively visit the function body with incremented depth\n visitor(declaration.body, depth + 1);\n }\n }\n }\n }\n\n ts.forEachChild(node, (child) => visitor(child, depth));\n };\n\n visitor(node, 0);\n return tokens;\n};\n\nconst logger = debug('@sdk-it/generic');\n\nconst jsDocsTags = [\n 'openapi',\n 'tags',\n 'description',\n 'summary',\n 'access',\n 'tool',\n 'toolDescription',\n] as const;\ntype JSDocsTags = (typeof jsDocsTags)[number];\n\nfunction parseJSDocComment(node: ts.Node) {\n let tags: string[] = [];\n let name = '';\n let description = '';\n let summary = '';\n let access = '';\n let tool = '';\n let toolDescription = '';\n\n for (const tag of ts.getAllJSDocTags(node, (tag): tag is ts.JSDocTag =>\n jsDocsTags.includes(tag.tagName.text as JSDocsTags),\n )) {\n if (typeof tag.comment !== 'string') {\n continue;\n }\n switch (tag.tagName.text as JSDocsTags) {\n case 'openapi':\n name = tag.comment;\n break;\n case 'tags':\n tags = tag.comment.split(',').map((tag) => tag.trim());\n break;\n case 'description':\n description = tag.comment;\n break;\n case 'summary':\n summary = tag.comment;\n break;\n case 'access':\n access = tag.comment.trim().toLowerCase();\n break;\n case 'tool':\n tool = tag.comment.trim();\n break;\n case 'toolDescription':\n toolDescription = tag.comment.trim();\n break;\n }\n }\n return {\n name,\n tags,\n description,\n access,\n tool,\n toolDescription,\n summary,\n };\n}\n\nfunction visit(\n node: ts.Node,\n responseAnalyzer: (\n handler: ts.ArrowFunction | ts.FunctionExpression,\n token: string,\n node: ts.Node,\n ) => ResponseItem[],\n paths: Paths,\n typeChecker: ts.TypeChecker,\n typeDeriver: TypeDeriver,\n) {\n if (!ts.isCallExpression(node) || node.arguments.length < 2) {\n return moveOn();\n }\n if (\n !ts.isPropertyAccessExpression(node.expression) ||\n !ts.isIdentifier(node.expression.name) ||\n !isHttpMethod(node.expression.name.text)\n ) {\n return moveOn();\n }\n\n const [pathNode] = node.arguments;\n if (!ts.isStringLiteral(pathNode)) {\n return moveOn();\n }\n const method = node.expression.name.text;\n const path = pathNode.text;\n const validate = node.arguments.find((arg) =>\n isCallExpression(arg, 'validate'),\n );\n if (!validate) {\n return moveOn();\n }\n const handler = node.arguments.at(-1);\n if (!handler || !ts.isArrowFunction(handler)) {\n return moveOn();\n }\n const metadata = parseJSDocComment(node.parent);\n // Skip endpoints marked as private access\n if (metadata.access === 'private') {\n return moveOn();\n }\n const operationName =\n metadata.name ||\n camelcase(`${method} ${path.replace(/[^a-zA-Z0-9]/g, '')}`);\n if (!validate.arguments.length) {\n return moveOn();\n }\n\n let selector: ts.Expression | undefined;\n let contentType: ts.Expression | undefined;\n if (validate.arguments.length === 2) {\n contentType = validate.arguments[0];\n selector = validate.arguments[1];\n } else {\n selector = validate.arguments[0];\n }\n if (!ts.isArrowFunction(selector)) {\n return moveOn();\n }\n if (\n !selector ||\n !ts.isParenthesizedExpression(selector.body) ||\n !ts.isObjectLiteralExpression(selector.body.expression)\n ) {\n return moveOn();\n }\n\n // Collect all middleware declarations for analysis\n const middlewareDeclarations: { node: ts.Node; name?: string }[] = [];\n\n // slice(1, -1) to skip first (path) and last (handler) arguments\n // and skip the validate middleware - it's handled separately\n for (const arg of node.arguments.slice(1, -1)) {\n if (ts.isCallExpression(arg)) {\n // Try to resolve the factory function declaration\n if (ts.isIdentifier(arg.expression)) {\n const middlewareFnName = arg.expression.text;\n let symbol = typeChecker.getSymbolAtLocation(arg.expression);\n\n // If symbol has alias, resolve to the actual symbol\n if (symbol && symbol.flags & ts.SymbolFlags.Alias) {\n symbol = typeChecker.getAliasedSymbol(symbol);\n }\n\n const allDeclarations = [\n symbol?.valueDeclaration,\n ...(symbol?.declarations ?? []),\n ].filter((it) => !!it);\n\n let declaration = allDeclarations.find(isFunctionWithBody);\n\n // If not found, check for variable declarations with function initializers\n if (!declaration) {\n for (const decl of allDeclarations) {\n if (ts.isVariableDeclaration(decl) && decl.initializer) {\n if (isFunctionWithBody(decl.initializer)) {\n declaration = decl.initializer;\n break;\n }\n }\n }\n }\n\n if (declaration) {\n middlewareDeclarations.push({\n node: declaration,\n name: middlewareFnName,\n });\n }\n }\n\n // Also check if the call expression argument itself is an arrow function\n // e.g., middleware((ctx) => {...})\n // But skip if the function name is 'validate'\n if (\n ts.isIdentifier(arg.expression) &&\n arg.expression.text === 'validate'\n ) {\n continue;\n }\n const firstArg = arg.arguments[0];\n if (isFunctionWithBody(firstArg)) {\n middlewareDeclarations.push({ node: firstArg });\n }\n }\n }\n\n const props = selector.body.expression.properties.filter(\n ts.isPropertyAssignment,\n );\n\n const sourceFile = node.getSourceFile();\n\n typeDeriver.setTrace({\n file: sourceFile.fileName,\n operation: `${method.toUpperCase()} ${path}`,\n });\n\n const responses: ResponseItem[] = [];\n\n // Analyze all middlewares for potential responses\n for (const middleware of middlewareDeclarations) {\n for (const { token, node } of returnTokens(middleware.node, typeChecker)) {\n const items = responseAnalyzer(middleware.node as any, token, node);\n if (middleware.name) {\n for (const item of items) {\n item.middlewareName = middleware.name;\n }\n }\n responses.push(...items);\n }\n }\n\n // Analyze the main handler for responses\n for (const { token, node } of returnTokens(handler, typeChecker)) {\n responses.push(...responseAnalyzer(handler, token, node));\n }\n\n paths.addPath(\n operationName,\n path,\n method,\n contentType\n ? ts.isStringLiteral(contentType)\n ? contentType.text\n : undefined\n : undefined,\n toSelectors(props),\n responses,\n sourceFile.fileName,\n metadata,\n );\n\n function moveOn() {\n ts.forEachChild(node, (node) =>\n visit(node, responseAnalyzer, paths, typeChecker, typeDeriver),\n );\n }\n}\n\nfunction toSelectors(props: ts.PropertyAssignment[]) {\n const selectors: Selector[] = [];\n for (const prop of props) {\n if (!ts.isObjectLiteralExpression(prop.initializer)) {\n continue;\n }\n const name = prop.name.getText();\n const select = prop.initializer.properties\n .filter(ts.isPropertyAssignment)\n .find((prop) => prop.name.getText() === 'select');\n if (!select) {\n console.warn(\n `\\u26a0 No select found in ${name}\\n at ${nodeLocation(prop) ?? 'unknown'}`,\n );\n continue;\n }\n const against = prop.initializer.properties\n .filter(ts.isPropertyAssignment)\n .find((prop) => prop.name.getText() === 'against');\n if (!against) {\n console.warn(\n `\\u26a0 No against found in ${name}\\n at ${nodeLocation(prop) ?? 'unknown'}`,\n );\n continue;\n }\n const [, source, selectText] = select.initializer.getText().split('.');\n selectors.push({\n name: selectText,\n against: against.initializer.getText(),\n source: source as SemanticSource,\n });\n }\n return selectors;\n}\n\nexport async function analyze(\n tsconfigPath: string,\n config: {\n /**\n * Additional code to inject before resolving zod schemas\n */\n imports?: InjectImport[];\n typesMap?: Record<string, string>;\n responseAnalyzer: ResponseAnalyzerFn | NaunceResponseAnalyzer;\n onOperation?: OnOperation;\n },\n) {\n logger(`Parsing tsconfig`);\n const program = getProgram(tsconfigPath);\n logger(`Program created`);\n const typeChecker = program.getTypeChecker();\n\n logger(`Type checker created`);\n const typeDeriver = new TypeDeriver(typeChecker, config.typesMap);\n const paths = new Paths({\n imports: config.imports ?? [],\n onOperation: config.onOperation,\n });\n\n for (const sourceFile of program.getSourceFiles()) {\n logger(`Analyzing ${sourceFile.fileName}`);\n if (!sourceFile.isDeclarationFile) {\n logger(`Visiting ${sourceFile.fileName}`);\n visit(\n sourceFile,\n (handler, token, node) => {\n const responseAnalyzer = config.responseAnalyzer;\n if (typeof responseAnalyzer !== 'function') {\n const naunce =\n responseAnalyzer[token] || responseAnalyzer['default'];\n if (!naunce) {\n throw new Error(`No response analyzer for token ${token}`);\n }\n return naunce(handler, typeDeriver, node);\n }\n return responseAnalyzer(handler, typeDeriver);\n },\n paths,\n typeChecker,\n typeDeriver,\n );\n }\n }\n\n const components: ComponentsObject = {\n schemas: {\n ...paths.getSharedSchemas(),\n ...Object.entries(typeDeriver.collector).reduce(\n (acc, [key, value]) => ({ ...acc, [key]: toSchema(value) }),\n {},\n ),\n },\n };\n\n return {\n paths: await paths.getPaths(),\n tags: paths.getTags(),\n components,\n };\n}\n\nexport type Serialized = ReturnType<typeof analyze>;\n\nfunction isFunctionWithBody(\n node: ts.Node | ts.Declaration | undefined,\n): node is ts.FunctionLikeDeclaration & { body: ts.Block | ts.Expression } {\n if (!node) {\n return false;\n }\n return (\n (ts.isFunctionDeclaration(node) ||\n ts.isFunctionExpression(node) ||\n ts.isArrowFunction(node) ||\n ts.isMethodDeclaration(node) ||\n ts.isConstructorDeclaration(node) ||\n ts.isGetAccessor(node) ||\n ts.isSetAccessor(node)) &&\n !!node.body\n );\n}\n", "import ts from 'typescript';\n\nimport type {\n NaunceResponseAnalyzer,\n ResponseItem,\n TypeDeriver,\n} from '@sdk-it/core';\n\nconst handlerVisitor: (\n on: (\n node: ts.Node | undefined,\n statusCode: ts.Node | undefined,\n headers: ts.Node | undefined,\n contentType: string,\n ) => void,\n) => ts.Visitor = (callback) => {\n return (node: ts.Node) => {\n if (ts.isReturnStatement(node) && node.expression) {\n if (\n ts.isCallExpression(node.expression) &&\n ts.isPropertyAccessExpression(node.expression.expression)\n ) {\n const propAccess = node.expression.expression;\n if (\n ts.isIdentifier(propAccess.expression) &&\n propAccess.expression.text === 'output'\n ) {\n let contentType = 'application/json';\n const callerMethod = propAccess.name.text;\n const [body, statusCode, headers] = node.expression.arguments;\n if (callerMethod === 'attachment') {\n contentType = 'application/octet-stream';\n }\n if (!body) {\n contentType = 'empty';\n }\n callback(body, statusCode, headers, contentType);\n }\n }\n }\n return ts.forEachChild(node, handlerVisitor(callback));\n };\n};\n\nfunction toResponses(\n handler: ts.ArrowFunction | ts.FunctionExpression,\n deriver: TypeDeriver,\n) {\n const responsesList: ResponseItem[] = [];\n const visit = handlerVisitor((node, statusCode, headers, contentType) => {\n responsesList.push({\n headers: headers ? Object.keys(deriver.serializeNode(headers)) : [],\n contentType,\n statusCode: statusCode ? resolveStatusCode(statusCode) : '200',\n response: node ? deriver.serializeNode(node) : undefined,\n });\n });\n visit(handler.body);\n return responsesList;\n}\n\nfunction resolveStatusCode(node: ts.Node) {\n if (ts.isNumericLiteral(node)) {\n return node.text;\n }\n throw new Error(`Could not resolve status code`);\n}\n\nexport function defaultResponseAnalyzer(\n handler: ts.ArrowFunction | ts.FunctionExpression,\n deriver: TypeDeriver,\n) {\n try {\n return toResponses(handler, deriver);\n } catch (error) {\n console.error('Error analyzing response\\n', handler.getText());\n throw error;\n }\n}\n\nexport const responseAnalyzer: NaunceResponseAnalyzer = {\n 'throw.new.ProblemDetailsException': (handler, deriver, node) => {\n if (ts.isNewExpression(node)) {\n const [problem] = node.arguments ?? [];\n if (!ts.isObjectLiteralExpression(problem)) {\n return [];\n }\n const properties = problem.properties.reduce<Record<string, string>>(\n (acc, prop) => {\n if (ts.isPropertyAssignment(prop)) {\n const key = prop.name.getText();\n if (ts.isLiteralExpression(prop.initializer)) {\n acc[key] = prop.initializer.text;\n } else {\n acc[key] = prop.initializer.getText();\n }\n }\n return acc;\n },\n {},\n );\n return [\n {\n contentType: 'application/problem+json',\n headers: [],\n statusCode: properties.status,\n response: deriver.serializeNode(problem),\n },\n ];\n }\n return [];\n },\n default: defaultResponseAnalyzer,\n};\n\nexport default responseAnalyzer;\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,WAAW;AAElB,SAAS,iBAAiB;AAC1B,OAAO,QAAQ;AAEf;AAAA,EAIE;AAAA,EAKA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKP,SAAS,WAAW,QAAmD;AACrE,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,QAAM,eAAe,OAAO,gBAAgB,CAAC;AAC7C,MAAI,aAAa,WAAW,GAAG;AAC7B,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,aA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;AACX;",
|
|
6
6
|
"names": ["node", "tag", "responseAnalyzer", "prop", "ts", "visit"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/lib/generic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAEhB,KAAK,kBAAkB,EAUxB,MAAM,cAAc,CAAC;AAsCtB,eAAO,MAAM,YAAY,GACvB,MAAM,EAAE,CAAC,IAAI,EACb,cAAc,EAAE,CAAC,WAAW,EAC5B,UAAU;IAAE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE;WAEpC,MAAM;UAAQ,EAAE,CAAC,UAAU;GAsFnD,CAAC;
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/lib/generic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAEhB,KAAK,kBAAkB,EAUxB,MAAM,cAAc,CAAC;AAsCtB,eAAO,MAAM,YAAY,GACvB,MAAM,EAAE,CAAC,IAAI,EACb,cAAc,EAAE,CAAC,WAAW,EAC5B,UAAU;IAAE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE;WAEpC,MAAM;UAAQ,EAAE,CAAC,UAAU;GAsFnD,CAAC;AA0RF,wBAAsB,OAAO,CAC3B,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE;IACN;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,gBAAgB,EAAE,kBAAkB,GAAG,sBAAsB,CAAC;IAC9D,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;;;;GAsDF;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdk-it/generic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"!**/*.test.*"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@sdk-it/core": "0.
|
|
25
|
+
"@sdk-it/core": "0.46.1",
|
|
26
26
|
"stringcase": "^4.3.1",
|
|
27
27
|
"debug": "^4.4.0",
|
|
28
28
|
"openapi3-ts": "^4.4.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"typescript": "^
|
|
31
|
+
"typescript": "^6.0.3"
|
|
32
32
|
}
|
|
33
33
|
}
|