vovk 3.0.0-draft.388 → 3.0.0-draft.389

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.
@@ -59,7 +59,7 @@ function generateTypeScriptCode({ handlerName, rpcName, packageName, queryValida
59
59
  sampleValue = `"${(0, getJSONSchemaExample_1.getSampleValue)(schema)}"`;
60
60
  }
61
61
  const desc = schema.description ?? description;
62
- return `\nformData.append("${key}", ${sampleValue});${desc ? ` // ${desc}` : ''}`;
62
+ return `\n${desc ? `// ${desc}\n` : ''}formData.append("${key}", ${sampleValue});`;
63
63
  };
64
64
  const tsArgs = hasArg
65
65
  ? `{
@@ -108,17 +108,17 @@ function generatePythonCode({ handlerName, rpcName, packageName, queryValidation
108
108
  return getPySample(noFileSchema);
109
109
  };
110
110
  const getFileTouple = (schema) => {
111
- const desc = schema.description;
112
- return `('name.ext', BytesIO(${isTextFormat(schema.contentMediaType) ? '"text_content".encode("utf-8")' : 'binary_data'}${schema.contentMediaType ? `, "${schema.contentMediaType}"` : ''}))${desc ? ` # ${desc}` : ''}`;
111
+ return `('name.ext', BytesIO(${isTextFormat(schema.contentMediaType) ? '"text_content".encode("utf-8")' : 'binary_data'}${schema.contentMediaType ? `, "${schema.contentMediaType}"` : ''}))`;
113
112
  };
114
113
  const getPyFiles = (schema) => {
115
114
  return Object.entries(schema.properties ?? {}).reduce((acc, [key, prop]) => {
116
115
  const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
116
+ const desc = target.description ?? prop.description ?? undefined;
117
117
  if (target.type === 'string' && target.format === 'binary') {
118
- acc.push(`${getIndentSpaces(8)}('${key}', ${getFileTouple(target)})`);
118
+ acc.push(`${desc ? `${getIndentSpaces(8)}# ${desc}\n` : ''}${getIndentSpaces(8)}('${key}', ${getFileTouple(target)})`);
119
119
  }
120
120
  else if (target.type === 'array' && target.items?.format === 'binary') {
121
- const val = `${getIndentSpaces(8)}('${key}', ${getFileTouple(target.items)})`;
121
+ const val = `${desc ? `${getIndentSpaces(8)}# ${desc}\n` : ''}${getIndentSpaces(8)}('${key}', ${getFileTouple(target.items)})`;
122
122
  acc.push(val, val);
123
123
  }
124
124
  return acc;
@@ -126,7 +126,7 @@ function generatePythonCode({ handlerName, rpcName, packageName, queryValidation
126
126
  };
127
127
  const pyFiles = bodyValidation ? getPyFiles(bodyValidation) : null;
128
128
  const pyFilesArg = pyFiles?.length
129
- ? `${getIndentSpaces(4)}files=[\n${pyFiles.join(',\n')}${getIndentSpaces(4)}\n]`
129
+ ? `${getIndentSpaces(4)}files=[\n${pyFiles.join(',\n')}${getIndentSpaces(4)}\n],`
130
130
  : null;
131
131
  const PY_CODE = `from ${packageName} import ${rpcName}
132
132
 
@@ -215,7 +215,7 @@ function generateRustCode({ handlerName, rpcName, packageName, queryValidation,
215
215
  sampleValue = `"${(0, getJSONSchemaExample_1.getSampleValue)(schema)}"`;
216
216
  }
217
217
  const desc = schema.description ?? description;
218
- return `\n${getIndentSpaces(4)}.part("${key}", ${sampleValue});${desc ? ` // ${desc}` : ''}`;
218
+ return `\n${getIndentSpaces(4)}${desc ? `// ${desc}\n` : ''}${getIndentSpaces(4)}.part("${key}", ${sampleValue});`;
219
219
  };
220
220
  const getBody = (schema) => {
221
221
  if (schema['x-isForm']) {
@@ -92,7 +92,7 @@ function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes,
92
92
  return '[]';
93
93
  const items = value.map((item) => {
94
94
  const itemSchema = schema.items || {};
95
- const formattedItem = formatWithDescriptions(item, itemSchema, rootSchema, comment, stripQuotes, indent + 2);
95
+ const formattedItem = formatWithDescriptions(item, itemSchema, rootSchema, comment, stripQuotes, indent + 4);
96
96
  return `${indentStr} ${formattedItem}`;
97
97
  });
98
98
  return `[\n${items.join(',\n')}\n${indentStr}]`;
@@ -130,7 +130,7 @@ function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes,
130
130
  // Format the key
131
131
  const formattedKey = stripQuotes && /^[A-Za-z_$][0-9A-Za-z_$]*$/.test(key) ? key : JSON.stringify(key);
132
132
  // Format the value
133
- const formattedValue = formatWithDescriptions(val, resolvedPropSchema, rootSchema, comment, stripQuotes, indent + 2);
133
+ const formattedValue = formatWithDescriptions(val, resolvedPropSchema, rootSchema, comment, stripQuotes, indent + 4);
134
134
  formattedEntries.push(`${indentStr} ${formattedKey}: ${formattedValue}${index < entries.length - 1 ? ',' : ''}`);
135
135
  });
136
136
  return `{\n${formattedEntries.join('\n')}\n${indentStr}}`;
@@ -59,7 +59,7 @@ function generateTypeScriptCode({ handlerName, rpcName, packageName, queryValida
59
59
  sampleValue = `"${(0, getJSONSchemaExample_1.getSampleValue)(schema)}"`;
60
60
  }
61
61
  const desc = schema.description ?? description;
62
- return `\nformData.append("${key}", ${sampleValue});${desc ? ` // ${desc}` : ''}`;
62
+ return `\n${desc ? `// ${desc}\n` : ''}formData.append("${key}", ${sampleValue});`;
63
63
  };
64
64
  const tsArgs = hasArg
65
65
  ? `{
@@ -108,17 +108,17 @@ function generatePythonCode({ handlerName, rpcName, packageName, queryValidation
108
108
  return getPySample(noFileSchema);
109
109
  };
110
110
  const getFileTouple = (schema) => {
111
- const desc = schema.description;
112
- return `('name.ext', BytesIO(${isTextFormat(schema.contentMediaType) ? '"text_content".encode("utf-8")' : 'binary_data'}${schema.contentMediaType ? `, "${schema.contentMediaType}"` : ''}))${desc ? ` # ${desc}` : ''}`;
111
+ return `('name.ext', BytesIO(${isTextFormat(schema.contentMediaType) ? '"text_content".encode("utf-8")' : 'binary_data'}${schema.contentMediaType ? `, "${schema.contentMediaType}"` : ''}))`;
113
112
  };
114
113
  const getPyFiles = (schema) => {
115
114
  return Object.entries(schema.properties ?? {}).reduce((acc, [key, prop]) => {
116
115
  const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
116
+ const desc = target.description ?? prop.description ?? undefined;
117
117
  if (target.type === 'string' && target.format === 'binary') {
118
- acc.push(`${getIndentSpaces(8)}('${key}', ${getFileTouple(target)})`);
118
+ acc.push(`${desc ? `${getIndentSpaces(8)}# ${desc}\n` : ''}${getIndentSpaces(8)}('${key}', ${getFileTouple(target)})`);
119
119
  }
120
120
  else if (target.type === 'array' && target.items?.format === 'binary') {
121
- const val = `${getIndentSpaces(8)}('${key}', ${getFileTouple(target.items)})`;
121
+ const val = `${desc ? `${getIndentSpaces(8)}# ${desc}\n` : ''}${getIndentSpaces(8)}('${key}', ${getFileTouple(target.items)})`;
122
122
  acc.push(val, val);
123
123
  }
124
124
  return acc;
@@ -126,7 +126,7 @@ function generatePythonCode({ handlerName, rpcName, packageName, queryValidation
126
126
  };
127
127
  const pyFiles = bodyValidation ? getPyFiles(bodyValidation) : null;
128
128
  const pyFilesArg = pyFiles?.length
129
- ? `${getIndentSpaces(4)}files=[\n${pyFiles.join(',\n')}${getIndentSpaces(4)}\n]`
129
+ ? `${getIndentSpaces(4)}files=[\n${pyFiles.join(',\n')}${getIndentSpaces(4)}\n],`
130
130
  : null;
131
131
  const PY_CODE = `from ${packageName} import ${rpcName}
132
132
 
@@ -215,7 +215,7 @@ function generateRustCode({ handlerName, rpcName, packageName, queryValidation,
215
215
  sampleValue = `"${(0, getJSONSchemaExample_1.getSampleValue)(schema)}"`;
216
216
  }
217
217
  const desc = schema.description ?? description;
218
- return `\n${getIndentSpaces(4)}.part("${key}", ${sampleValue});${desc ? ` // ${desc}` : ''}`;
218
+ return `\n${getIndentSpaces(4)}${desc ? `// ${desc}\n` : ''}${getIndentSpaces(4)}.part("${key}", ${sampleValue});`;
219
219
  };
220
220
  const getBody = (schema) => {
221
221
  if (schema['x-isForm']) {
@@ -92,7 +92,7 @@ function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes,
92
92
  return '[]';
93
93
  const items = value.map((item) => {
94
94
  const itemSchema = schema.items || {};
95
- const formattedItem = formatWithDescriptions(item, itemSchema, rootSchema, comment, stripQuotes, indent + 2);
95
+ const formattedItem = formatWithDescriptions(item, itemSchema, rootSchema, comment, stripQuotes, indent + 4);
96
96
  return `${indentStr} ${formattedItem}`;
97
97
  });
98
98
  return `[\n${items.join(',\n')}\n${indentStr}]`;
@@ -130,7 +130,7 @@ function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes,
130
130
  // Format the key
131
131
  const formattedKey = stripQuotes && /^[A-Za-z_$][0-9A-Za-z_$]*$/.test(key) ? key : JSON.stringify(key);
132
132
  // Format the value
133
- const formattedValue = formatWithDescriptions(val, resolvedPropSchema, rootSchema, comment, stripQuotes, indent + 2);
133
+ const formattedValue = formatWithDescriptions(val, resolvedPropSchema, rootSchema, comment, stripQuotes, indent + 4);
134
134
  formattedEntries.push(`${indentStr} ${formattedKey}: ${formattedValue}${index < entries.length - 1 ? ',' : ''}`);
135
135
  });
136
136
  return `{\n${formattedEntries.join('\n')}\n${indentStr}}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "3.0.0-draft.388",
3
+ "version": "3.0.0-draft.389",
4
4
  "main": "./cjs/index.js",
5
5
  "module": "./mjs/index.js",
6
6
  "types": "./mjs/index.d.ts",