@sdk-it/generic 0.5.1 → 0.6.0
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 +117 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +2 -2
- package/dist/lib/generic.d.ts +2 -1
- package/dist/lib/generic.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# @sdk-it/generic
|
|
2
|
+
|
|
3
|
+
<p align="center">A TypeScript analysis tool for generating OpenAPI specifications from TypeScript code</p>
|
|
4
|
+
|
|
5
|
+
This package provides tools to analyze TypeScript code and generate OpenAPI specifications from it. It can extract route information, parameter types, and response schemas from your TypeScript codebase.
|
|
6
|
+
|
|
7
|
+
## Integration with Other Frameworks
|
|
8
|
+
|
|
9
|
+
- [hono](../hono/README.md)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @sdk-it/generic
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Consider the following example:
|
|
20
|
+
|
|
21
|
+
- Create a route using your API framework of choice with the `@openapi` tag and validate middleware.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import z from 'zod';
|
|
25
|
+
|
|
26
|
+
import { validate } from '@sdk-it/express';
|
|
27
|
+
|
|
28
|
+
const app = express();
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @openapi getAuthor
|
|
32
|
+
* @tags authors
|
|
33
|
+
*/
|
|
34
|
+
app.get(
|
|
35
|
+
'/authors/:id',
|
|
36
|
+
validate((payload) => ({
|
|
37
|
+
id: {
|
|
38
|
+
select: payload.param.id,
|
|
39
|
+
against: z.string(),
|
|
40
|
+
},
|
|
41
|
+
})),
|
|
42
|
+
async (c) => {
|
|
43
|
+
const author = [{ name: 'John Doe' }];
|
|
44
|
+
return c.json(author);
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- Use the generate fn to create an OpenAPI spec from your routes.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { join } from 'node:path';
|
|
53
|
+
|
|
54
|
+
import { analyze, responseAnalyzer } from '@sdk-it/generic';
|
|
55
|
+
import { generate } from '@sdk-it/typescript';
|
|
56
|
+
|
|
57
|
+
const { paths, components } = await analyze('path/to/tsconfig.json', {
|
|
58
|
+
responseAnalyzer,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Now you can use the generated specification to create an SDK or save it to a file
|
|
62
|
+
const spec = {
|
|
63
|
+
info: {
|
|
64
|
+
title: 'My API',
|
|
65
|
+
version: '1.0.0',
|
|
66
|
+
},
|
|
67
|
+
paths,
|
|
68
|
+
components,
|
|
69
|
+
};
|
|
70
|
+
await generate(spec, {
|
|
71
|
+
output: join(process.cwd(), './client'),
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
> [!TIP]
|
|
76
|
+
> See [typescript](../typescript/README.md) for more info.
|
|
77
|
+
|
|
78
|
+
### Customizing Operations
|
|
79
|
+
|
|
80
|
+
You can customize the operations as well as add more through the `onOperation` fn.
|
|
81
|
+
|
|
82
|
+
**Use file name as tag**
|
|
83
|
+
|
|
84
|
+
Assuming your projects structurd like the following where routes are grouped by representivie file names.
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
apps/
|
|
88
|
+
backend/
|
|
89
|
+
tsconfig.app.json
|
|
90
|
+
src/
|
|
91
|
+
routes/
|
|
92
|
+
authors.ts
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Then you can consider the file name as the tag for the operation which means you don't need to specify the tag in the JSDoc comment or only specify the tag if you want to override the default behavior.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { basename } from 'node:path';
|
|
99
|
+
import { camelcase } from 'stringcase';
|
|
100
|
+
|
|
101
|
+
import { analyze, responseAnalyzer } from '@sdk-it/generic';
|
|
102
|
+
|
|
103
|
+
const { paths, components } = await analyze('apps/backend/tsconfig.app.json', {
|
|
104
|
+
responseAnalyzer,
|
|
105
|
+
onOperation(sourceFile, method, path, operation) {
|
|
106
|
+
const fileName = basename(sourceFile.split('/').at(-1), '.ts');
|
|
107
|
+
return {
|
|
108
|
+
[method]: {
|
|
109
|
+
[path]: {
|
|
110
|
+
...operation,
|
|
111
|
+
tags: [fileName],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -73,12 +73,14 @@ function visit(node, responseAnalyzer2, paths) {
|
|
|
73
73
|
const props = selector.body.expression.properties.filter(
|
|
74
74
|
ts.isPropertyAssignment
|
|
75
75
|
);
|
|
76
|
+
const sourceFile = node.getSourceFile();
|
|
76
77
|
paths.addPath(
|
|
77
78
|
operationName,
|
|
78
79
|
path,
|
|
79
80
|
method,
|
|
80
81
|
toSelectors(props),
|
|
81
82
|
responseAnalyzer2(handler),
|
|
83
|
+
sourceFile.fileName,
|
|
82
84
|
metadata.tags,
|
|
83
85
|
metadata.description
|
|
84
86
|
);
|
|
@@ -123,7 +125,8 @@ async function analyze(tsconfigPath, config) {
|
|
|
123
125
|
logger(`Type checker created`);
|
|
124
126
|
const typeDeriver = new TypeDeriver(typeChecker);
|
|
125
127
|
const paths = new Paths({
|
|
126
|
-
commonZodImport: config.commonZodImport
|
|
128
|
+
commonZodImport: config.commonZodImport,
|
|
129
|
+
onOperation: config.onOperation
|
|
127
130
|
});
|
|
128
131
|
for (const sourceFile of program.getSourceFiles()) {
|
|
129
132
|
if (!sourceFile.isDeclarationFile) {
|
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
|
|
5
|
-
"mappings": ";AAAA,OAAO,WAAW;
|
|
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 OnOperation,\n Paths,\n type ResponseItem,\n type Selector,\n type SemanticSource,\n TypeDeriver,\n getProgram,\n isCallExpression,\n isHttpMethod,\n toSchema,\n} from '@sdk-it/core';\n\nconst logger = debug('@sdk-it/generic');\n\nconst jsDocsTags = ['openapi', 'tags', 'description'];\n\nfunction parseJSDocComment(node: ts.Node) {\n let tags: string[] = [];\n let name = '';\n let description = '';\n for (const tag of ts.getAllJSDocTags(node, (tag): tag is ts.JSDocTag =>\n jsDocsTags.includes(tag.tagName.text),\n )) {\n if (typeof tag.comment !== 'string') {\n continue;\n }\n switch (tag.tagName.text) {\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 }\n }\n return {\n name,\n tags,\n description,\n };\n}\n\nfunction visit(\n node: ts.Node,\n responseAnalyzer: (handler: ts.ArrowFunction) => ResponseItem[],\n paths: Paths,\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\n const metadata = parseJSDocComment(node.parent);\n const operationName =\n metadata.name ||\n camelcase(`${method} ${path.replace(/[^a-zA-Z0-9]/g, '')}`);\n const selector = validate.arguments.find((arg) => ts.isArrowFunction(arg));\n if (\n !selector ||\n !ts.isParenthesizedExpression(selector.body) ||\n !ts.isObjectLiteralExpression(selector.body.expression)\n ) {\n return moveOn();\n }\n const props = selector.body.expression.properties.filter(\n ts.isPropertyAssignment,\n );\n\n const sourceFile = node.getSourceFile();\n paths.addPath(\n operationName,\n path,\n method,\n toSelectors(props),\n responseAnalyzer(handler),\n sourceFile.fileName,\n metadata.tags,\n metadata.description,\n );\n\n function moveOn() {\n ts.forEachChild(node, (node) => visit(node, responseAnalyzer, paths));\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(`No select found in ${name}`);\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(`No against found in ${name}`);\n continue;\n }\n const [, source, selectText] = select.initializer.getText().split('.');\n selectors.push({\n name,\n nullable: against.initializer.getText().includes('nullable'),\n required: !against.initializer.getText().includes('optional'),\n select: 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 commonZodImport?: string;\n responseAnalyzer: (\n handler: ts.ArrowFunction,\n deriver: TypeDeriver,\n ) => ResponseItem[];\n onOperation?: OnOperation;\n },\n) {\n logger(`Parsing tsconfig`);\n const program = getProgram(tsconfigPath);\n logger(`Program created`);\n const typeChecker = program.getTypeChecker();\n logger(`Type checker created`);\n const typeDeriver = new TypeDeriver(typeChecker);\n const paths = new Paths({\n commonZodImport: config.commonZodImport,\n onOperation: config.onOperation,\n });\n for (const sourceFile of program.getSourceFiles()) {\n if (!sourceFile.isDeclarationFile) {\n logger(`Visiting ${sourceFile.fileName}`);\n visit(\n sourceFile,\n (handler) => config.responseAnalyzer(handler, typeDeriver),\n paths,\n );\n }\n }\n\n const components: ComponentsObject = {\n schemas: Object.entries(typeDeriver.collector).reduce(\n (acc, [key, value]) => ({ ...acc, [key]: toSchema(value) }),\n {},\n ),\n };\n\n return {\n paths: await paths.getPaths(),\n components,\n };\n}\n\nexport type Serialized = ReturnType<typeof analyze>;\n", "import ts from 'typescript';\n\nimport type { ResponseItem, TypeDeriver } from '@sdk-it/core';\n\nconst visitor: (\n on: (\n node: ts.Node,\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 if (callerMethod === 'attachment') {\n contentType = 'application/octet-stream';\n }\n const [body, statusCode, headers] = node.expression.arguments;\n callback(body, statusCode, headers, contentType);\n }\n }\n }\n return ts.forEachChild(node, visitor(callback));\n };\n};\n\nfunction toResponses(handler: ts.ArrowFunction, deriver: TypeDeriver) {\n const responsesList: ResponseItem[] = [];\n const visit = visitor((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 responseAnalyzer(\n handler: ts.ArrowFunction,\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"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,WAAW;AAElB,SAAS,iBAAiB;AAC1B,OAAO,QAAQ;AAEf;AAAA,EAEE;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,IAAM,SAAS,MAAM,iBAAiB;AAEtC,IAAM,aAAa,CAAC,WAAW,QAAQ,aAAa;AAEpD,SAAS,kBAAkB,MAAe;AACxC,MAAI,OAAiB,CAAC;AACtB,MAAI,OAAO;AACX,MAAI,cAAc;AAClB,aAAW,OAAO,GAAG;AAAA,IAAgB;AAAA,IAAM,CAACA,SAC1C,WAAW,SAASA,KAAI,QAAQ,IAAI;AAAA,EACtC,GAAG;AACD,QAAI,OAAO,IAAI,YAAY,UAAU;AACnC;AAAA,IACF;AACA,YAAQ,IAAI,QAAQ,MAAM;AAAA,MACxB,KAAK;AACH,eAAO,IAAI;AACX;AAAA,MACF,KAAK;AACH,eAAO,IAAI,QAAQ,MAAM,GAAG,EAAE,IAAI,CAACA,SAAQA,KAAI,KAAK,CAAC;AACrD;AAAA,MACF,KAAK;AACH,sBAAc,IAAI;AAClB;AAAA,IACJ;AAAA,EACF;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,MACP,MACAC,mBACA,OACA;AACA,MAAI,CAAC,GAAG,iBAAiB,IAAI,KAAK,KAAK,UAAU,SAAS,GAAG;AAC3D,WAAO,OAAO;AAAA,EAChB;AACA,MACE,CAAC,GAAG,2BAA2B,KAAK,UAAU,KAC9C,CAAC,GAAG,aAAa,KAAK,WAAW,IAAI,KACrC,CAAC,aAAa,KAAK,WAAW,KAAK,IAAI,GACvC;AACA,WAAO,OAAO;AAAA,EAChB;AAEA,QAAM,CAAC,QAAQ,IAAI,KAAK;AACxB,MAAI,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AU,OAAO,QAAQ,cAAc,IAAI,IAAI;AAAA,IACjD,CAAC;AAAA,EACH,CAAC;AACD,EAAAA,OAAM,QAAQ,IAAI;AAClB,SAAO;AACT;AAEA,SAAS,kBAAkB,MAAe;AACxC,MAAID,IAAG,iBAAiB,IAAI,GAAG;AAC7B,WAAO,KAAK;AAAA,EACd;AACA,QAAM,IAAI,MAAM,+BAA+B;AACjD;AAEO,SAAS,iBACd,SACA,SACA;AACA,MAAI;AACF,WAAO,YAAY,SAAS,OAAO;AAAA,EACrC,SAAS,OAAO;AACd,YAAQ,MAAM,8BAA8B,QAAQ,QAAQ,CAAC;AAC7D,UAAM;AAAA,EACR;AACF;",
|
|
6
6
|
"names": ["tag", "responseAnalyzer", "node", "prop", "ts", "visit"]
|
|
7
7
|
}
|
package/dist/lib/generic.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { ComponentsObject } from 'openapi3-ts/oas31';
|
|
2
2
|
import ts from 'typescript';
|
|
3
|
-
import { type ResponseItem, TypeDeriver } from '@sdk-it/core';
|
|
3
|
+
import { type OnOperation, type ResponseItem, TypeDeriver } from '@sdk-it/core';
|
|
4
4
|
export declare function analyze(tsconfigPath: string, config: {
|
|
5
5
|
/**
|
|
6
6
|
* Additional code to inject before resolving zod schemas
|
|
7
7
|
*/
|
|
8
8
|
commonZodImport?: string;
|
|
9
9
|
responseAnalyzer: (handler: ts.ArrowFunction, deriver: TypeDeriver) => ResponseItem[];
|
|
10
|
+
onOperation?: OnOperation;
|
|
10
11
|
}): Promise<{
|
|
11
12
|
paths: import("openapi3-ts/oas31").PathsObject;
|
|
12
13
|
components: ComponentsObject;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/lib/generic.ts"],"names":[],"mappings":"
|
|
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,WAAW,EAEhB,KAAK,YAAY,EAGjB,WAAW,EAKZ,MAAM,cAAc,CAAC;AAuItB,wBAAsB,OAAO,CAC3B,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE;IACN;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,CAChB,OAAO,EAAE,EAAE,CAAC,aAAa,EACzB,OAAO,EAAE,WAAW,KACjB,YAAY,EAAE,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;;;GAkCF;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.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"!**/*.tsbuildinfo"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@sdk-it/core": "0.
|
|
24
|
+
"@sdk-it/core": "0.6.0",
|
|
25
25
|
"stringcase": "^4.3.1",
|
|
26
26
|
"typescript": "^5.7.2",
|
|
27
27
|
"debug": "^4.4.0",
|