vovk 3.0.0-draft.386 → 3.0.0-draft.388

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.
@@ -99,19 +99,23 @@ function generatePythonCode({ handlerName, rpcName, packageName, queryValidation
99
99
  const noFileSchema = {
100
100
  ...schema,
101
101
  properties: schema.properties
102
- ? Object.fromEntries(Object.entries(schema.properties).filter(([, prop]) => prop.format !== 'binary' || prop.items?.format !== 'binary'))
102
+ ? Object.fromEntries(Object.entries(schema.properties).filter(([, prop]) => {
103
+ const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
104
+ return target.format !== 'binary' || target.items?.format !== 'binary';
105
+ }))
103
106
  : {},
104
107
  };
105
108
  return getPySample(noFileSchema);
106
109
  };
107
110
  const getFileTouple = (schema) => {
108
- return `('name.ext', BytesIO(${isTextFormat(schema.contentMediaType) ? '"text_content".encode("utf-8")' : 'binary_data'}${schema.contentMediaType ? `"${schema.contentMediaType}"` : ''}))`;
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}` : ''}`;
109
113
  };
110
114
  const getPyFiles = (schema) => {
111
115
  return Object.entries(schema.properties ?? {}).reduce((acc, [key, prop]) => {
112
116
  const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
113
- if (target.format === 'binary') {
114
- acc.push(`('${key}', ${getFileTouple(target)})`);
117
+ if (target.type === 'string' && target.format === 'binary') {
118
+ acc.push(`${getIndentSpaces(8)}('${key}', ${getFileTouple(target)})`);
115
119
  }
116
120
  else if (target.type === 'array' && target.items?.format === 'binary') {
117
121
  const val = `${getIndentSpaces(8)}('${key}', ${getFileTouple(target.items)})`;
@@ -121,7 +125,9 @@ function generatePythonCode({ handlerName, rpcName, packageName, queryValidation
121
125
  }, []);
122
126
  };
123
127
  const pyFiles = bodyValidation ? getPyFiles(bodyValidation) : null;
124
- const pyFilesArg = pyFiles?.length ? `${getIndentSpaces(4)}files=[\n${pyFiles.join(',\n')}\n]` : null;
128
+ const pyFilesArg = pyFiles?.length
129
+ ? `${getIndentSpaces(4)}files=[\n${pyFiles.join(',\n')}${getIndentSpaces(4)}\n]`
130
+ : null;
125
131
  const PY_CODE = `from ${packageName} import ${rpcName}
126
132
 
127
133
  response = ${rpcName}.${handlerNameSnake}(${hasArg
@@ -99,19 +99,23 @@ function generatePythonCode({ handlerName, rpcName, packageName, queryValidation
99
99
  const noFileSchema = {
100
100
  ...schema,
101
101
  properties: schema.properties
102
- ? Object.fromEntries(Object.entries(schema.properties).filter(([, prop]) => prop.format !== 'binary' || prop.items?.format !== 'binary'))
102
+ ? Object.fromEntries(Object.entries(schema.properties).filter(([, prop]) => {
103
+ const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
104
+ return target.format !== 'binary' || target.items?.format !== 'binary';
105
+ }))
103
106
  : {},
104
107
  };
105
108
  return getPySample(noFileSchema);
106
109
  };
107
110
  const getFileTouple = (schema) => {
108
- return `('name.ext', BytesIO(${isTextFormat(schema.contentMediaType) ? '"text_content".encode("utf-8")' : 'binary_data'}${schema.contentMediaType ? `"${schema.contentMediaType}"` : ''}))`;
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}` : ''}`;
109
113
  };
110
114
  const getPyFiles = (schema) => {
111
115
  return Object.entries(schema.properties ?? {}).reduce((acc, [key, prop]) => {
112
116
  const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
113
- if (target.format === 'binary') {
114
- acc.push(`('${key}', ${getFileTouple(target)})`);
117
+ if (target.type === 'string' && target.format === 'binary') {
118
+ acc.push(`${getIndentSpaces(8)}('${key}', ${getFileTouple(target)})`);
115
119
  }
116
120
  else if (target.type === 'array' && target.items?.format === 'binary') {
117
121
  const val = `${getIndentSpaces(8)}('${key}', ${getFileTouple(target.items)})`;
@@ -121,7 +125,9 @@ function generatePythonCode({ handlerName, rpcName, packageName, queryValidation
121
125
  }, []);
122
126
  };
123
127
  const pyFiles = bodyValidation ? getPyFiles(bodyValidation) : null;
124
- const pyFilesArg = pyFiles?.length ? `${getIndentSpaces(4)}files=[\n${pyFiles.join(',\n')}\n]` : null;
128
+ const pyFilesArg = pyFiles?.length
129
+ ? `${getIndentSpaces(4)}files=[\n${pyFiles.join(',\n')}${getIndentSpaces(4)}\n]`
130
+ : null;
125
131
  const PY_CODE = `from ${packageName} import ${rpcName}
126
132
 
127
133
  response = ${rpcName}.${handlerNameSnake}(${hasArg
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "3.0.0-draft.386",
3
+ "version": "3.0.0-draft.388",
4
4
  "main": "./cjs/index.js",
5
5
  "module": "./mjs/index.js",
6
6
  "types": "./mjs/index.d.ts",