vovk-cli 0.0.1-draft.243 → 0.0.1-draft.245
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.
|
@@ -9,29 +9,8 @@ export function convertJSONSchemaToTypeScriptDef(schema) {
|
|
|
9
9
|
const escapeJSDocComment = (str) => {
|
|
10
10
|
return str.replace(/\*\//g, '*\\/');
|
|
11
11
|
};
|
|
12
|
-
// Process schema and any nested definitions
|
|
13
|
-
const processSchema = (currentSchema) => {
|
|
14
|
-
// Merge any $defs into the main schema for reference resolution
|
|
15
|
-
if (currentSchema.$defs || currentSchema.definitions) {
|
|
16
|
-
// Create a copy to avoid modifying the original
|
|
17
|
-
const processedSchema = { ...currentSchema };
|
|
18
|
-
// Support both $defs (JSON Schema 2019-09+) and definitions (older JSON Schema)
|
|
19
|
-
if (!processedSchema.definitions) {
|
|
20
|
-
processedSchema.definitions = {};
|
|
21
|
-
}
|
|
22
|
-
// Copy $defs into definitions for consistent reference resolution
|
|
23
|
-
if (processedSchema.$defs) {
|
|
24
|
-
processedSchema.definitions = {
|
|
25
|
-
...processedSchema.definitions,
|
|
26
|
-
...processedSchema.$defs,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
return processedSchema;
|
|
30
|
-
}
|
|
31
|
-
return currentSchema;
|
|
32
|
-
};
|
|
33
12
|
// Pre-process the schema to handle definitions
|
|
34
|
-
const processedSchema =
|
|
13
|
+
const processedSchema = schema;
|
|
35
14
|
// Helper function to resolve $ref references
|
|
36
15
|
const resolveRef = (ref) => {
|
|
37
16
|
if (!ref.startsWith('#/'))
|
|
@@ -208,8 +187,27 @@ export function convertJSONSchemaToTypeScriptDef(schema) {
|
|
|
208
187
|
return 'undefined';
|
|
209
188
|
}
|
|
210
189
|
};
|
|
190
|
+
// Preprocess schema to extract $defs into top level for easier reference resolution
|
|
191
|
+
function extractDefinitions(inputSchema) {
|
|
192
|
+
// Create a shallow copy to avoid modifying the original
|
|
193
|
+
const resultSchema = { ...inputSchema };
|
|
194
|
+
// Move $defs to definitions for compatibility
|
|
195
|
+
if (resultSchema.$defs && !resultSchema.definitions) {
|
|
196
|
+
resultSchema.definitions = resultSchema.$defs;
|
|
197
|
+
}
|
|
198
|
+
return resultSchema;
|
|
199
|
+
}
|
|
200
|
+
const schemaWithExtractedDefs = extractDefinitions(schema);
|
|
211
201
|
// Generate the interface
|
|
212
|
-
const jsDoc = getJSDoc(
|
|
213
|
-
|
|
202
|
+
const jsDoc = getJSDoc(schemaWithExtractedDefs);
|
|
203
|
+
let interfaceBody;
|
|
204
|
+
try {
|
|
205
|
+
interfaceBody = schemaToType(schemaWithExtractedDefs);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
// eslint-disable-next-line no-console
|
|
209
|
+
console.error('Error generating TypeScript definition:', error);
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
214
212
|
return `${jsDoc}\n${interfaceBody}`;
|
|
215
213
|
}
|