@pikku/openapi-parser 0.12.9 → 0.12.11
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/CHANGELOG.md +22 -0
- package/dist/codegen.d.ts +1 -0
- package/dist/codegen.js +586 -66
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/naming.d.ts +7 -0
- package/dist/naming.js +136 -11
- package/dist/openapi-to-zod-schema.d.ts +20 -7
- package/dist/openapi-to-zod-schema.js +245 -33
- package/dist/parse-openapi.js +22 -9
- package/dist/zod-codegen.d.ts +1 -1
- package/dist/zod-codegen.js +1 -1
- package/package.json +2 -2
- package/src/codegen.test.ts +782 -0
- package/src/codegen.ts +726 -74
- package/src/index.ts +2 -3
- package/src/naming.test.ts +260 -0
- package/src/naming.ts +155 -14
- package/src/openapi-to-zod-schema.test.ts +664 -0
- package/src/openapi-to-zod-schema.ts +270 -35
- package/src/parse-openapi.test.ts +23 -8
- package/src/parse-openapi.ts +22 -9
- package/src/zod-codegen.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
package/dist/parse-openapi.js
CHANGED
|
@@ -93,13 +93,17 @@ export async function parseOpenAPISpec(filePath) {
|
|
|
93
93
|
tagDescriptions,
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
|
-
/** Recursively resolve $ref pointers in-place */
|
|
97
|
-
function resolveRefs(node, root) {
|
|
96
|
+
/** Recursively resolve $ref pointers in-place, with cycle detection */
|
|
97
|
+
function resolveRefs(node, root, visited) {
|
|
98
98
|
if (node === null || typeof node !== 'object')
|
|
99
99
|
return node;
|
|
100
|
+
const seen = visited ?? new Set();
|
|
101
|
+
if (seen.has(node))
|
|
102
|
+
return node;
|
|
103
|
+
seen.add(node);
|
|
100
104
|
if (Array.isArray(node)) {
|
|
101
105
|
for (let i = 0; i < node.length; i++) {
|
|
102
|
-
node[i] = resolveRefs(node[i], root);
|
|
106
|
+
node[i] = resolveRefs(node[i], root, seen);
|
|
103
107
|
}
|
|
104
108
|
return node;
|
|
105
109
|
}
|
|
@@ -109,13 +113,14 @@ function resolveRefs(node, root) {
|
|
|
109
113
|
// Merge any sibling properties (like description overrides)
|
|
110
114
|
const { $ref, ...siblings } = node;
|
|
111
115
|
const result = { ...resolved, ...siblings };
|
|
112
|
-
// Don't recurse
|
|
116
|
+
// Don't recurse into the merged result — it shares structure with
|
|
117
|
+
// the original resolved object and may be circular
|
|
113
118
|
return result;
|
|
114
119
|
}
|
|
115
120
|
return node;
|
|
116
121
|
}
|
|
117
122
|
for (const key of Object.keys(node)) {
|
|
118
|
-
node[key] = resolveRefs(node[key], root);
|
|
123
|
+
node[key] = resolveRefs(node[key], root, seen);
|
|
119
124
|
}
|
|
120
125
|
return node;
|
|
121
126
|
}
|
|
@@ -342,10 +347,18 @@ export function computeContractHash(spec) {
|
|
|
342
347
|
securitySchemes: spec.securitySchemes,
|
|
343
348
|
serverUrls: spec.serverUrls,
|
|
344
349
|
};
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
350
|
+
// Use a cycle-safe JSON serializer since resolved $ref schemas
|
|
351
|
+
// can contain circular object references
|
|
352
|
+
const seen = new WeakSet();
|
|
353
|
+
const json = JSON.stringify(contract, (_key, value) => {
|
|
354
|
+
if (typeof value === 'object' && value !== null) {
|
|
355
|
+
if (seen.has(value))
|
|
356
|
+
return '[Circular]';
|
|
357
|
+
seen.add(value);
|
|
358
|
+
}
|
|
359
|
+
return value;
|
|
360
|
+
});
|
|
361
|
+
return createHash('sha256').update(json).digest('hex').slice(0, 16);
|
|
349
362
|
}
|
|
350
363
|
function extractTagDescriptions(doc) {
|
|
351
364
|
const result = {};
|
package/dist/zod-codegen.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { type OpenAPISchema, type ZodCodegenContext, createContext, schemaToZod, schemaVarName, sanitizeTypeName, } from './openapi-to-zod-schema.js';
|
|
1
|
+
export { type OpenAPISchema, type ZodCodegenContext, createContext, schemaToZod, schemaVarName, sanitizeTypeName, snakeToCamel, } from './openapi-to-zod-schema.js';
|
package/dist/zod-codegen.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createContext, schemaToZod, schemaVarName, sanitizeTypeName, } from './openapi-to-zod-schema.js';
|
|
1
|
+
export { createContext, schemaToZod, schemaVarName, sanitizeTypeName, snakeToCamel, } from './openapi-to-zod-schema.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/openapi-parser",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.11",
|
|
4
4
|
"description": "OpenAPI spec parser and code generator for Pikku",
|
|
5
5
|
"author": "yasser.fadl@gmail.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
"yaml": "^2.7.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"typescript": "^
|
|
24
|
+
"typescript": "^6.0.3"
|
|
25
25
|
}
|
|
26
26
|
}
|