@stackql/provider-utils 0.4.7 → 0.4.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackql/provider-utils",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "description": "Utilities for building StackQL providers from OpenAPI specifications.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -38,6 +38,11 @@ export function sanitizeHtml(text) {
38
38
  .replace(/<code>/g, '___CODE_OPEN___')
39
39
  .replace(/<\/code>/g, '___CODE_CLOSE___');
40
40
 
41
+ // Remove <nobr> tags completely
42
+ result = result
43
+ .replace(/<nobr>/g, '')
44
+ .replace(/<\/nobr>/g, '');
45
+
41
46
  // Then apply the general sanitization
42
47
  result = result
43
48
  .replace(/{/g, '&#123;')
@@ -69,7 +74,7 @@ export function sanitizeHtml(text) {
69
74
  result = result
70
75
  .replace(/___CODE_OPEN___/g, '<code>')
71
76
  .replace(/___CODE_CLOSE___/g, '</code>');
72
-
77
+
73
78
  return result;
74
79
  }
75
80
 
@@ -371,8 +376,8 @@ function getHttpOperationInfo(dereferencedAPI, path, httpVerb, mediaType, openAP
371
376
  throw new Error(`HTTP verb '${httpVerb}' not found for path '${path}'`);
372
377
  }
373
378
 
374
- // Get operation description and replace curly braces with HTML entities
375
- const opDescription = (dereferencedAPI.paths[path][httpVerb].description || ''); // .replace(/\{/g, '&#123;').replace(/\}/g, '&#125;');
379
+ // Get operation description
380
+ const opDescription = (dereferencedAPI.paths[path][httpVerb].description || '');
376
381
 
377
382
  // Extract request body if it exists
378
383
  let requestBody = {};
@@ -384,19 +389,69 @@ function getHttpOperationInfo(dereferencedAPI, path, httpVerb, mediaType, openAP
384
389
  if (contentTypes.length > 0) {
385
390
  const firstContentType = contentTypes[0];
386
391
  const reqBodySchema = dereferencedAPI.paths[path][httpVerb].requestBody.content[firstContentType].schema;
392
+
387
393
  if (reqBodySchema) {
388
- // If schema is a reference, use it directly
389
- if (reqBodySchema.$ref) {
394
+ // Handle polymorphic schemas (anyOf/oneOf) - pick the first one but preserve original structure
395
+ if ((reqBodySchema.anyOf && reqBodySchema.anyOf.length > 0) ||
396
+ (reqBodySchema.oneOf && reqBodySchema.oneOf.length > 0)) {
397
+
398
+ // Start with the original schema to preserve its structure
399
+ requestBody = { ...reqBodySchema };
400
+
401
+ // Select the first schema
402
+ const schemas = reqBodySchema.anyOf || reqBodySchema.oneOf;
403
+ const firstSchema = schemas[0];
404
+
405
+ // Extract properties from first schema
406
+ if (firstSchema.$ref) {
407
+ // If it's a reference, we need to add it as a property
408
+ requestBody.$firstSchema = firstSchema;
409
+ } else if (firstSchema.properties) {
410
+ // If it has properties, use them as our main properties
411
+ requestBody.properties = firstSchema.properties;
412
+ requestBody.required = firstSchema.required || [];
413
+ } else {
414
+ // Otherwise, merge all properties from first schema
415
+ Object.assign(requestBody, firstSchema);
416
+ }
417
+
418
+ // Additional check: if there's an example, use it to extract properties
419
+ // that might be expected by other parts of the code
420
+ const example = dereferencedAPI.paths[path][httpVerb].requestBody.content[firstContentType].example;
421
+ if (example) {
422
+ // Ensure properties object exists
423
+ if (!requestBody.properties) {
424
+ requestBody.properties = {};
425
+ }
426
+
427
+ // Add properties from example that aren't already defined
428
+ Object.keys(example).forEach(key => {
429
+ if (!requestBody.properties[key]) {
430
+ // Create a simple property definition based on the example value
431
+ const value = example[key];
432
+ const type = typeof value === 'number' ? 'number' :
433
+ typeof value === 'boolean' ? 'boolean' : 'string';
434
+
435
+ requestBody.properties[key] = {
436
+ type: type,
437
+ example: value
438
+ };
439
+ }
440
+ });
441
+ }
442
+ }
443
+ // If schema is a reference, use it directly (unchanged)
444
+ else if (reqBodySchema.$ref) {
390
445
  requestBody = reqBodySchema;
391
446
  }
392
- // If schema is an object with properties, get them
447
+ // If schema is an object with properties, get them (unchanged)
393
448
  else if (reqBodySchema.properties) {
394
449
  requestBody = {
395
450
  properties: reqBodySchema.properties,
396
451
  required: reqBodySchema.required || []
397
452
  };
398
453
  }
399
- // If schema is something else, use it as is
454
+ // If schema is something else, use it as is (unchanged)
400
455
  else {
401
456
  requestBody = reqBodySchema;
402
457
  }
@@ -404,7 +459,7 @@ function getHttpOperationInfo(dereferencedAPI, path, httpVerb, mediaType, openAP
404
459
  }
405
460
  }
406
461
 
407
- // Check if the response exists
462
+ // Rest of the function remains unchanged
408
463
  if (!dereferencedAPI.paths[path][httpVerb].responses ||
409
464
  !dereferencedAPI.paths[path][httpVerb].responses[openAPIDocKey]) {
410
465
  console.warn(`Response '${openAPIDocKey}' not found for ${path}/${httpVerb}`);
@@ -161,9 +161,17 @@ export function createInsertExamples(providerName, serviceName, resourceName, re
161
161
  content += ' value: ' + type + '\n';
162
162
 
163
163
  if (description) {
164
- // Format multi-line descriptions
165
- const wrappedDesc = description.replace(/(.{1,80})(\\s+|$)/g, '$1\n ');
166
- content += ' description: >\n ' + wrappedDesc + '\n';
164
+ content += ' description: |\n';
165
+
166
+ // Split by lines and remove empty lines
167
+ const lines = description
168
+ .split(/\n/)
169
+ .filter(line => line.trim() !== ''); // Remove completely empty lines
170
+
171
+ // Process each line with proper indentation
172
+ lines.forEach(line => {
173
+ content += ' ' + line.trim() + '\n'; // trim each line to remove extra spaces
174
+ });
167
175
  }
168
176
 
169
177
  // Add enum values if available