vovk 3.0.0-draft.382 → 3.0.0-draft.384

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.
@@ -33,7 +33,7 @@ function isTextFormat(mimeType) {
33
33
  function generateTypeScriptCode({ handlerName, rpcName, packageName, queryValidation, bodyValidation, paramsValidation, outputValidation, iterationValidation, hasArg, }) {
34
34
  const getTsSample = (schema, indent) => (0, getJSONSchemaExample_1.getJSONSchemaExample)(schema, { stripQuotes: true, indent: indent ?? 4 });
35
35
  const getTsFormSample = (schema) => {
36
- let formSample = 'const formData = new FormData();';
36
+ let formSample = '\nconst formData = new FormData();';
37
37
  for (const [key, prop] of Object.entries(schema.properties || {})) {
38
38
  const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
39
39
  const desc = target.description ?? prop.description ?? undefined;
@@ -44,24 +44,6 @@ function generateTypeScriptCode({ handlerName, rpcName, packageName, queryValida
44
44
  else {
45
45
  formSample += getTsFormAppend(target, key, desc);
46
46
  }
47
- /* if (target.type === 'string' && target.format === 'binary') {
48
- sampleValue = `new Blob(${isTextFormat(target.contentMediaType) ? '["text_content"]' : '[binary_data]'}${
49
- target.contentMediaType ? `, { type: "${target.contentMediaType}" }` : ''
50
- })`;
51
- } else if (target.type === 'array') {
52
- if (nesting === 0 && target.items) {
53
- sampleValue +=
54
- getTsFormSample(target.items, indent, nesting + 1) + getTsFormSample(target.items, indent, nesting + 1);
55
- } else {
56
- sampleValue += '"array_unknown"';
57
- }
58
- } else if (target.type === 'object') {
59
- sampleValue += '"object_unknown"';
60
- } else {
61
- sampleValue += `"${getSampleValue(target)}"`;
62
- }
63
-
64
- formSample += `\n${getIndentSpaces(4)}form.append("${key}", ${sampleValue});`; */
65
47
  }
66
48
  return formSample;
67
49
  };
@@ -166,38 +148,69 @@ ${outputValidation ? `print(response)\n${getPySample(outputValidation, 0)}` : ''
166
148
  function generateRustCode({ handlerName, rpcName, packageName, queryValidation, bodyValidation, paramsValidation, outputValidation, iterationValidation, }) {
167
149
  const getRsJSONSample = (schema, indent) => (0, getJSONSchemaExample_1.getJSONSchemaExample)(schema, { stripQuotes: false, indent: indent ?? 4 });
168
150
  const getRsOutputSample = (schema, indent) => (0, getJSONSchemaExample_1.getJSONSchemaExample)(schema, { stripQuotes: true, indent: indent ?? 4 });
169
- const getRsFormSample = (schema, indent, nesting = 0) => {
151
+ /* const getRsFormSample = (schema: VovkSimpleJSONSchema, indent?: number, nesting = 0) => {
152
+ let formSample = 'let form = multipart::Form::new()';
153
+ for (const [key, prop] of Object.entries(schema.properties || {})) {
154
+ const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
155
+ let sampleValue; // = value.type === 'object' ? 'object_unknown' : getSampleValue(value);
156
+ if (target.type === 'string' && target.format === 'binary') {
157
+ sampleValue = isTextFormat(target.contentMediaType)
158
+ ? 'multipart::Part::text("text_content")'
159
+ : 'multipart::Part::bytes(binary_data)';
160
+
161
+ if (target.contentMediaType) {
162
+ sampleValue += `.mime_str("${target.contentMediaType}").unwrap()`;
163
+ }
164
+ } else if (prop.type === 'array') {
165
+ if (nesting === 0 && prop.items) {
166
+ sampleValue =
167
+ getRsFormSample(prop.items, indent, nesting + 1) + getRsFormSample(prop.items, indent, nesting + 1);
168
+ } else {
169
+ sampleValue = '"array_unknown"';
170
+ }
171
+ } else if (target.type === 'object') {
172
+ sampleValue = '"object_unknown"';
173
+ } else {
174
+ sampleValue = `"${getSampleValue(target)}"`;
175
+ }
176
+ formSample += `\n${getIndentSpaces(4)}.part("${key}", ${sampleValue});`;
177
+ }
178
+ return formSample;
179
+ }; */
180
+ const getRsFormSample = (schema) => {
170
181
  let formSample = 'let form = multipart::Form::new()';
171
182
  for (const [key, prop] of Object.entries(schema.properties || {})) {
172
183
  const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
173
- let sampleValue; // = value.type === 'object' ? 'object_unknown' : getSampleValue(value);
174
- if (target.type === 'string' && target.format === 'binary') {
175
- sampleValue = isTextFormat(target.contentMediaType)
176
- ? 'multipart::Part::text("text_content")'
177
- : 'multipart::Part::bytes(binary_data)';
178
- if (target.contentMediaType) {
179
- sampleValue += `.mime_str("${target.contentMediaType}").unwrap()`;
180
- }
181
- }
182
- else if (prop.type === 'array') {
183
- if (nesting === 0 && prop.items) {
184
- sampleValue =
185
- getRsFormSample(prop.items, indent, nesting + 1) + getRsFormSample(prop.items, indent, nesting + 1);
186
- }
187
- else {
188
- sampleValue = '"array_unknown"';
189
- }
190
- }
191
- else if (target.type === 'object') {
192
- sampleValue = '"object_unknown"';
184
+ const desc = target.description ?? prop.description ?? undefined;
185
+ if (target.type === 'array' && target.items) {
186
+ formSample += getRsFormPart(target.items, key, desc);
187
+ formSample += getRsFormPart(target.items, key, desc);
193
188
  }
194
189
  else {
195
- sampleValue = `"${(0, getJSONSchemaExample_1.getSampleValue)(target)}"`;
190
+ formSample += getRsFormPart(target, key, desc);
196
191
  }
197
- formSample += `\n${getIndentSpaces(4)}.part("${key}", ${sampleValue});`;
198
192
  }
199
193
  return formSample;
200
194
  };
195
+ const getRsFormPart = (schema, key, description) => {
196
+ let sampleValue;
197
+ if (schema.type === 'string' && schema.format === 'binary') {
198
+ sampleValue = isTextFormat(schema.contentMediaType)
199
+ ? 'multipart::Part::text("text_content")'
200
+ : 'multipart::Part::bytes(binary_data)';
201
+ if (schema.contentMediaType) {
202
+ sampleValue += `.mime_str("${schema.contentMediaType}").unwrap()`;
203
+ }
204
+ }
205
+ else if (schema.type === 'object') {
206
+ sampleValue = '"object_unknown"';
207
+ }
208
+ else {
209
+ sampleValue = `"${(0, getJSONSchemaExample_1.getSampleValue)(schema)}"`;
210
+ }
211
+ const desc = schema.description ?? description;
212
+ return `\n${getIndentSpaces(4)}.part("${key}", ${sampleValue});${desc ? ` // ${desc}` : ''}`;
213
+ };
201
214
  const getBody = (schema) => {
202
215
  if (schema['x-isForm']) {
203
216
  return 'form';
@@ -33,7 +33,7 @@ function isTextFormat(mimeType) {
33
33
  function generateTypeScriptCode({ handlerName, rpcName, packageName, queryValidation, bodyValidation, paramsValidation, outputValidation, iterationValidation, hasArg, }) {
34
34
  const getTsSample = (schema, indent) => (0, getJSONSchemaExample_1.getJSONSchemaExample)(schema, { stripQuotes: true, indent: indent ?? 4 });
35
35
  const getTsFormSample = (schema) => {
36
- let formSample = 'const formData = new FormData();';
36
+ let formSample = '\nconst formData = new FormData();';
37
37
  for (const [key, prop] of Object.entries(schema.properties || {})) {
38
38
  const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
39
39
  const desc = target.description ?? prop.description ?? undefined;
@@ -44,24 +44,6 @@ function generateTypeScriptCode({ handlerName, rpcName, packageName, queryValida
44
44
  else {
45
45
  formSample += getTsFormAppend(target, key, desc);
46
46
  }
47
- /* if (target.type === 'string' && target.format === 'binary') {
48
- sampleValue = `new Blob(${isTextFormat(target.contentMediaType) ? '["text_content"]' : '[binary_data]'}${
49
- target.contentMediaType ? `, { type: "${target.contentMediaType}" }` : ''
50
- })`;
51
- } else if (target.type === 'array') {
52
- if (nesting === 0 && target.items) {
53
- sampleValue +=
54
- getTsFormSample(target.items, indent, nesting + 1) + getTsFormSample(target.items, indent, nesting + 1);
55
- } else {
56
- sampleValue += '"array_unknown"';
57
- }
58
- } else if (target.type === 'object') {
59
- sampleValue += '"object_unknown"';
60
- } else {
61
- sampleValue += `"${getSampleValue(target)}"`;
62
- }
63
-
64
- formSample += `\n${getIndentSpaces(4)}form.append("${key}", ${sampleValue});`; */
65
47
  }
66
48
  return formSample;
67
49
  };
@@ -166,38 +148,69 @@ ${outputValidation ? `print(response)\n${getPySample(outputValidation, 0)}` : ''
166
148
  function generateRustCode({ handlerName, rpcName, packageName, queryValidation, bodyValidation, paramsValidation, outputValidation, iterationValidation, }) {
167
149
  const getRsJSONSample = (schema, indent) => (0, getJSONSchemaExample_1.getJSONSchemaExample)(schema, { stripQuotes: false, indent: indent ?? 4 });
168
150
  const getRsOutputSample = (schema, indent) => (0, getJSONSchemaExample_1.getJSONSchemaExample)(schema, { stripQuotes: true, indent: indent ?? 4 });
169
- const getRsFormSample = (schema, indent, nesting = 0) => {
151
+ /* const getRsFormSample = (schema: VovkSimpleJSONSchema, indent?: number, nesting = 0) => {
152
+ let formSample = 'let form = multipart::Form::new()';
153
+ for (const [key, prop] of Object.entries(schema.properties || {})) {
154
+ const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
155
+ let sampleValue; // = value.type === 'object' ? 'object_unknown' : getSampleValue(value);
156
+ if (target.type === 'string' && target.format === 'binary') {
157
+ sampleValue = isTextFormat(target.contentMediaType)
158
+ ? 'multipart::Part::text("text_content")'
159
+ : 'multipart::Part::bytes(binary_data)';
160
+
161
+ if (target.contentMediaType) {
162
+ sampleValue += `.mime_str("${target.contentMediaType}").unwrap()`;
163
+ }
164
+ } else if (prop.type === 'array') {
165
+ if (nesting === 0 && prop.items) {
166
+ sampleValue =
167
+ getRsFormSample(prop.items, indent, nesting + 1) + getRsFormSample(prop.items, indent, nesting + 1);
168
+ } else {
169
+ sampleValue = '"array_unknown"';
170
+ }
171
+ } else if (target.type === 'object') {
172
+ sampleValue = '"object_unknown"';
173
+ } else {
174
+ sampleValue = `"${getSampleValue(target)}"`;
175
+ }
176
+ formSample += `\n${getIndentSpaces(4)}.part("${key}", ${sampleValue});`;
177
+ }
178
+ return formSample;
179
+ }; */
180
+ const getRsFormSample = (schema) => {
170
181
  let formSample = 'let form = multipart::Form::new()';
171
182
  for (const [key, prop] of Object.entries(schema.properties || {})) {
172
183
  const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
173
- let sampleValue; // = value.type === 'object' ? 'object_unknown' : getSampleValue(value);
174
- if (target.type === 'string' && target.format === 'binary') {
175
- sampleValue = isTextFormat(target.contentMediaType)
176
- ? 'multipart::Part::text("text_content")'
177
- : 'multipart::Part::bytes(binary_data)';
178
- if (target.contentMediaType) {
179
- sampleValue += `.mime_str("${target.contentMediaType}").unwrap()`;
180
- }
181
- }
182
- else if (prop.type === 'array') {
183
- if (nesting === 0 && prop.items) {
184
- sampleValue =
185
- getRsFormSample(prop.items, indent, nesting + 1) + getRsFormSample(prop.items, indent, nesting + 1);
186
- }
187
- else {
188
- sampleValue = '"array_unknown"';
189
- }
190
- }
191
- else if (target.type === 'object') {
192
- sampleValue = '"object_unknown"';
184
+ const desc = target.description ?? prop.description ?? undefined;
185
+ if (target.type === 'array' && target.items) {
186
+ formSample += getRsFormPart(target.items, key, desc);
187
+ formSample += getRsFormPart(target.items, key, desc);
193
188
  }
194
189
  else {
195
- sampleValue = `"${(0, getJSONSchemaExample_1.getSampleValue)(target)}"`;
190
+ formSample += getRsFormPart(target, key, desc);
196
191
  }
197
- formSample += `\n${getIndentSpaces(4)}.part("${key}", ${sampleValue});`;
198
192
  }
199
193
  return formSample;
200
194
  };
195
+ const getRsFormPart = (schema, key, description) => {
196
+ let sampleValue;
197
+ if (schema.type === 'string' && schema.format === 'binary') {
198
+ sampleValue = isTextFormat(schema.contentMediaType)
199
+ ? 'multipart::Part::text("text_content")'
200
+ : 'multipart::Part::bytes(binary_data)';
201
+ if (schema.contentMediaType) {
202
+ sampleValue += `.mime_str("${schema.contentMediaType}").unwrap()`;
203
+ }
204
+ }
205
+ else if (schema.type === 'object') {
206
+ sampleValue = '"object_unknown"';
207
+ }
208
+ else {
209
+ sampleValue = `"${(0, getJSONSchemaExample_1.getSampleValue)(schema)}"`;
210
+ }
211
+ const desc = schema.description ?? description;
212
+ return `\n${getIndentSpaces(4)}.part("${key}", ${sampleValue});${desc ? ` // ${desc}` : ''}`;
213
+ };
201
214
  const getBody = (schema) => {
202
215
  if (schema['x-isForm']) {
203
216
  return 'form';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "3.0.0-draft.382",
3
+ "version": "3.0.0-draft.384",
4
4
  "main": "./cjs/index.js",
5
5
  "module": "./mjs/index.js",
6
6
  "types": "./mjs/index.d.ts",