vovk 3.0.0-draft.392 → 3.0.0-draft.393
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.
|
@@ -3,6 +3,7 @@ interface SamplerOptions {
|
|
|
3
3
|
comment?: '//' | '#';
|
|
4
4
|
stripQuotes?: boolean;
|
|
5
5
|
indent?: number;
|
|
6
|
+
nestingIndent?: number;
|
|
6
7
|
ignoreBinary?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export declare function getJSONSchemaExample(schema: VovkSimpleJSONSchema, options: SamplerOptions, rootSchema?: VovkSimpleJSONSchema): string;
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getJSONSchemaExample = getJSONSchemaExample;
|
|
4
4
|
exports.getSampleValue = getSampleValue;
|
|
5
5
|
function getJSONSchemaExample(schema, options, rootSchema) {
|
|
6
|
-
const { comment = '//', stripQuotes = false, indent = 0,
|
|
6
|
+
const { comment = '//', stripQuotes = false, indent = 0, nestingIndent = 4, // Default to 4 spaces for backward compatibility
|
|
7
|
+
ignoreBinary = false, } = options;
|
|
7
8
|
if (!schema || typeof schema !== 'object')
|
|
8
9
|
return 'null';
|
|
9
10
|
// Use the input schema as the root if not provided
|
|
@@ -11,7 +12,7 @@ function getJSONSchemaExample(schema, options, rootSchema) {
|
|
|
11
12
|
// Get the sample value
|
|
12
13
|
const sampleValue = getSampleValue(schema, rootSchema, ignoreBinary);
|
|
13
14
|
// Format the output with descriptions
|
|
14
|
-
return formatWithDescriptions(sampleValue, schema, rootSchema, comment, stripQuotes, indent, ignoreBinary);
|
|
15
|
+
return formatWithDescriptions(sampleValue, schema, rootSchema, comment, stripQuotes, indent, nestingIndent, ignoreBinary);
|
|
15
16
|
}
|
|
16
17
|
function getSampleValue(schema, rootSchema, ignoreBinary) {
|
|
17
18
|
if (!schema || typeof schema !== 'object')
|
|
@@ -80,8 +81,10 @@ function getSampleValue(schema, rootSchema, ignoreBinary) {
|
|
|
80
81
|
// Default fallback
|
|
81
82
|
return null;
|
|
82
83
|
}
|
|
83
|
-
function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes, indent,
|
|
84
|
+
function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes, indent, nestingIndent, // Added parameter
|
|
85
|
+
ignoreBinary) {
|
|
84
86
|
const indentStr = ' '.repeat(indent);
|
|
87
|
+
const nestIndentStr = ' '.repeat(nestingIndent); // Create nesting indent string
|
|
85
88
|
// Handle undefined (for ignored binary fields)
|
|
86
89
|
if (value === undefined) {
|
|
87
90
|
return '';
|
|
@@ -100,8 +103,9 @@ function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes,
|
|
|
100
103
|
return '[]';
|
|
101
104
|
const items = value.map((item) => {
|
|
102
105
|
const itemSchema = schema.items || {};
|
|
103
|
-
const formattedItem = formatWithDescriptions(item, itemSchema, rootSchema, comment, stripQuotes, indent +
|
|
104
|
-
|
|
106
|
+
const formattedItem = formatWithDescriptions(item, itemSchema, rootSchema, comment, stripQuotes, indent + nestingIndent, // Use nestingIndent instead of hardcoded 4
|
|
107
|
+
nestingIndent, ignoreBinary);
|
|
108
|
+
return `${indentStr}${nestIndentStr}${formattedItem}`; // Use nestIndentStr for item indentation
|
|
105
109
|
});
|
|
106
110
|
return `[\n${items.join(',\n')}\n${indentStr}]`;
|
|
107
111
|
}
|
|
@@ -115,11 +119,11 @@ function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes,
|
|
|
115
119
|
// Add top-level description for objects
|
|
116
120
|
if (isTopLevel && schema.type === 'object' && schema.description) {
|
|
117
121
|
const descLines = schema.description.split('\n');
|
|
118
|
-
formattedEntries.push(`${indentStr}
|
|
122
|
+
formattedEntries.push(`${indentStr}${nestIndentStr}${comment} -----`);
|
|
119
123
|
descLines.forEach((line) => {
|
|
120
|
-
formattedEntries.push(`${indentStr}
|
|
124
|
+
formattedEntries.push(`${indentStr}${nestIndentStr}${comment} ${line.trim()}`);
|
|
121
125
|
});
|
|
122
|
-
formattedEntries.push(`${indentStr}
|
|
126
|
+
formattedEntries.push(`${indentStr}${nestIndentStr}${comment} -----`);
|
|
123
127
|
}
|
|
124
128
|
entries.forEach(([key, val], index) => {
|
|
125
129
|
const propSchema = schema.properties?.[key] ?? {};
|
|
@@ -132,14 +136,15 @@ function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes,
|
|
|
132
136
|
if (resolvedPropSchema.description) {
|
|
133
137
|
const descLines = resolvedPropSchema.description.split('\n');
|
|
134
138
|
descLines.forEach((line) => {
|
|
135
|
-
formattedEntries.push(`${indentStr}
|
|
139
|
+
formattedEntries.push(`${indentStr}${nestIndentStr}${comment} ${line.trim()}`);
|
|
136
140
|
});
|
|
137
141
|
}
|
|
138
142
|
// Format the key
|
|
139
143
|
const formattedKey = stripQuotes && /^[A-Za-z_$][0-9A-Za-z_$]*$/.test(key) ? key : JSON.stringify(key);
|
|
140
144
|
// Format the value
|
|
141
|
-
const formattedValue = formatWithDescriptions(val, resolvedPropSchema, rootSchema, comment, stripQuotes, indent +
|
|
142
|
-
|
|
145
|
+
const formattedValue = formatWithDescriptions(val, resolvedPropSchema, rootSchema, comment, stripQuotes, indent + nestingIndent, // Use nestingIndent instead of hardcoded 4
|
|
146
|
+
nestingIndent, ignoreBinary);
|
|
147
|
+
formattedEntries.push(`${indentStr}${nestIndentStr}${formattedKey}: ${formattedValue}${index < entries.length - 1 ? ',' : ''}`);
|
|
143
148
|
});
|
|
144
149
|
return `{\n${formattedEntries.join('\n')}\n${indentStr}}`;
|
|
145
150
|
}
|
|
@@ -3,6 +3,7 @@ interface SamplerOptions {
|
|
|
3
3
|
comment?: '//' | '#';
|
|
4
4
|
stripQuotes?: boolean;
|
|
5
5
|
indent?: number;
|
|
6
|
+
nestingIndent?: number;
|
|
6
7
|
ignoreBinary?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export declare function getJSONSchemaExample(schema: VovkSimpleJSONSchema, options: SamplerOptions, rootSchema?: VovkSimpleJSONSchema): string;
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getJSONSchemaExample = getJSONSchemaExample;
|
|
4
4
|
exports.getSampleValue = getSampleValue;
|
|
5
5
|
function getJSONSchemaExample(schema, options, rootSchema) {
|
|
6
|
-
const { comment = '//', stripQuotes = false, indent = 0,
|
|
6
|
+
const { comment = '//', stripQuotes = false, indent = 0, nestingIndent = 4, // Default to 4 spaces for backward compatibility
|
|
7
|
+
ignoreBinary = false, } = options;
|
|
7
8
|
if (!schema || typeof schema !== 'object')
|
|
8
9
|
return 'null';
|
|
9
10
|
// Use the input schema as the root if not provided
|
|
@@ -11,7 +12,7 @@ function getJSONSchemaExample(schema, options, rootSchema) {
|
|
|
11
12
|
// Get the sample value
|
|
12
13
|
const sampleValue = getSampleValue(schema, rootSchema, ignoreBinary);
|
|
13
14
|
// Format the output with descriptions
|
|
14
|
-
return formatWithDescriptions(sampleValue, schema, rootSchema, comment, stripQuotes, indent, ignoreBinary);
|
|
15
|
+
return formatWithDescriptions(sampleValue, schema, rootSchema, comment, stripQuotes, indent, nestingIndent, ignoreBinary);
|
|
15
16
|
}
|
|
16
17
|
function getSampleValue(schema, rootSchema, ignoreBinary) {
|
|
17
18
|
if (!schema || typeof schema !== 'object')
|
|
@@ -80,8 +81,10 @@ function getSampleValue(schema, rootSchema, ignoreBinary) {
|
|
|
80
81
|
// Default fallback
|
|
81
82
|
return null;
|
|
82
83
|
}
|
|
83
|
-
function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes, indent,
|
|
84
|
+
function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes, indent, nestingIndent, // Added parameter
|
|
85
|
+
ignoreBinary) {
|
|
84
86
|
const indentStr = ' '.repeat(indent);
|
|
87
|
+
const nestIndentStr = ' '.repeat(nestingIndent); // Create nesting indent string
|
|
85
88
|
// Handle undefined (for ignored binary fields)
|
|
86
89
|
if (value === undefined) {
|
|
87
90
|
return '';
|
|
@@ -100,8 +103,9 @@ function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes,
|
|
|
100
103
|
return '[]';
|
|
101
104
|
const items = value.map((item) => {
|
|
102
105
|
const itemSchema = schema.items || {};
|
|
103
|
-
const formattedItem = formatWithDescriptions(item, itemSchema, rootSchema, comment, stripQuotes, indent +
|
|
104
|
-
|
|
106
|
+
const formattedItem = formatWithDescriptions(item, itemSchema, rootSchema, comment, stripQuotes, indent + nestingIndent, // Use nestingIndent instead of hardcoded 4
|
|
107
|
+
nestingIndent, ignoreBinary);
|
|
108
|
+
return `${indentStr}${nestIndentStr}${formattedItem}`; // Use nestIndentStr for item indentation
|
|
105
109
|
});
|
|
106
110
|
return `[\n${items.join(',\n')}\n${indentStr}]`;
|
|
107
111
|
}
|
|
@@ -115,11 +119,11 @@ function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes,
|
|
|
115
119
|
// Add top-level description for objects
|
|
116
120
|
if (isTopLevel && schema.type === 'object' && schema.description) {
|
|
117
121
|
const descLines = schema.description.split('\n');
|
|
118
|
-
formattedEntries.push(`${indentStr}
|
|
122
|
+
formattedEntries.push(`${indentStr}${nestIndentStr}${comment} -----`);
|
|
119
123
|
descLines.forEach((line) => {
|
|
120
|
-
formattedEntries.push(`${indentStr}
|
|
124
|
+
formattedEntries.push(`${indentStr}${nestIndentStr}${comment} ${line.trim()}`);
|
|
121
125
|
});
|
|
122
|
-
formattedEntries.push(`${indentStr}
|
|
126
|
+
formattedEntries.push(`${indentStr}${nestIndentStr}${comment} -----`);
|
|
123
127
|
}
|
|
124
128
|
entries.forEach(([key, val], index) => {
|
|
125
129
|
const propSchema = schema.properties?.[key] ?? {};
|
|
@@ -132,14 +136,15 @@ function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes,
|
|
|
132
136
|
if (resolvedPropSchema.description) {
|
|
133
137
|
const descLines = resolvedPropSchema.description.split('\n');
|
|
134
138
|
descLines.forEach((line) => {
|
|
135
|
-
formattedEntries.push(`${indentStr}
|
|
139
|
+
formattedEntries.push(`${indentStr}${nestIndentStr}${comment} ${line.trim()}`);
|
|
136
140
|
});
|
|
137
141
|
}
|
|
138
142
|
// Format the key
|
|
139
143
|
const formattedKey = stripQuotes && /^[A-Za-z_$][0-9A-Za-z_$]*$/.test(key) ? key : JSON.stringify(key);
|
|
140
144
|
// Format the value
|
|
141
|
-
const formattedValue = formatWithDescriptions(val, resolvedPropSchema, rootSchema, comment, stripQuotes, indent +
|
|
142
|
-
|
|
145
|
+
const formattedValue = formatWithDescriptions(val, resolvedPropSchema, rootSchema, comment, stripQuotes, indent + nestingIndent, // Use nestingIndent instead of hardcoded 4
|
|
146
|
+
nestingIndent, ignoreBinary);
|
|
147
|
+
formattedEntries.push(`${indentStr}${nestIndentStr}${formattedKey}: ${formattedValue}${index < entries.length - 1 ? ',' : ''}`);
|
|
143
148
|
});
|
|
144
149
|
return `{\n${formattedEntries.join('\n')}\n${indentStr}}`;
|
|
145
150
|
}
|