@stackql/provider-utils 0.2.1 → 0.2.3

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.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Utilities for building StackQL providers from OpenAPI specifications.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -35,7 +35,7 @@
35
35
  "license": "MIT",
36
36
  "dependencies": {
37
37
  "@apidevtools/swagger-parser": "^10.1.1",
38
- "@stackql/deno-openapi-dereferencer": "npm:@jsr/stackql__deno-openapi-dereferencer@^0.3.0",
38
+ "@stackql/deno-openapi-dereferencer": "npm:@jsr/stackql__deno-openapi-dereferencer@^0.3.1",
39
39
  "js-yaml": "^4.1.0",
40
40
  "pluralize": "^8.0.0"
41
41
  },
@@ -18,10 +18,11 @@ export async function generateDocs(options) {
18
18
  console.log(`documenting ${providerName}...`);
19
19
 
20
20
  const docsDir = path.join(outputDir, `docs`);
21
+ const servicesDir = path.join(docsDir, `services`);
21
22
 
22
23
  // Remove directory if it exists, then create it fresh
23
24
  fs.existsSync(docsDir) && fs.rmSync(docsDir, { recursive: true, force: true });
24
- fs.mkdirSync(docsDir, { recursive: true });
25
+ fs.mkdirSync(servicesDir, { recursive: true });
25
26
 
26
27
  // Check for provider data files
27
28
  console.log(providerDataDir);
@@ -58,16 +59,16 @@ export async function generateDocs(options) {
58
59
  servicesForIndex.push(serviceName);
59
60
  const filePath = path.join(serviceDir, file);
60
61
  totalServicesCount++;
61
- const serviceFolder = `${docsDir}/${serviceName}`;
62
+ const serviceFolder = `${servicesDir}/${serviceName}`;
62
63
  await createDocsForService(filePath, providerName, serviceName, serviceFolder);
63
64
  }
64
65
 
65
66
  console.log(`Processed ${totalServicesCount} services`);
66
67
 
67
68
  // Count total resources
68
- totalResourcesCount = fs.readdirSync(`${docsDir}`, { withFileTypes: true })
69
+ totalResourcesCount = fs.readdirSync(`${servicesDir}`, { withFileTypes: true })
69
70
  .filter(dirent => dirent.isDirectory())
70
- .map(dirent => fs.readdirSync(`${docsDir}/${dirent.name}`).length)
71
+ .map(dirent => fs.readdirSync(`${servicesDir}/${dirent.name}`).length)
71
72
  .reduce((a, b) => a + b, 0);
72
73
 
73
74
  console.log(`Processed ${totalResourcesCount} resources`);
@@ -264,12 +265,12 @@ ${secondColumnLinks}
264
265
  function generateResourceLinks(providerName, serviceName, resources) {
265
266
  // Generate resource links for the service index
266
267
  const resourceLinks = resources.map((resource) => {
267
- return `<a href="/${serviceName}/${resource.name}/">${resource.name}</a>`;
268
+ return `<a href="/services/${serviceName}/${resource.name}/">${resource.name}</a>`;
268
269
  });
269
270
  return resourceLinks.join('<br />\n');
270
271
  }
271
272
 
272
273
  // Function to convert services to markdown links
273
274
  function servicesToMarkdown(providerName, servicesList) {
274
- return servicesList.map(service => `<a href="/${service}/">${service}</a><br />`).join('\n');
275
+ return servicesList.map(service => `<a href="/services/${service}/">${service}</a><br />`).join('\n');
275
276
  }
@@ -386,28 +386,87 @@ function getHttpOperationInfo(dereferencedAPI, path, httpVerb, mediaType, openAP
386
386
  }
387
387
 
388
388
  const schema = responseObj.content[mediaType].schema;
389
-
389
+
390
+ const { respProps, respDescription } = getHttpRespBody(schema, objectKey);
391
+
392
+ return {
393
+ respProps,
394
+ respDescription: responseObj.description ? responseObj.description : respDescription,
395
+ opDescription,
396
+ requestBody
397
+ };
398
+ }
399
+
400
+ // function getHttpRespBody(schema, objectKey) {
401
+
402
+ // if (schema.type === 'array') {
403
+ // return {
404
+ // respProps: schema.items.properties || {},
405
+ // respDescription: schema.items.description || '',
406
+ // }
407
+ // } else if (schema.type === 'object') {
408
+ // return {
409
+ // respProps: schema.properties || {},
410
+ // respDescription: schema.description || '',
411
+ // };
412
+ // } else {
413
+ // return {
414
+ // respProps: {},
415
+ // respDescription: '',
416
+ // };
417
+ // }
418
+
419
+
420
+ // }
421
+
422
+ function getHttpRespBody(schema, objectKey) {
423
+
390
424
  if (schema.type === 'array') {
391
425
  return {
392
- respProps: schema.items.properties || {},
393
- respDescription: schema.items.description || responseObj.description || '',
394
- opDescription,
395
- requestBody
396
- };
426
+ respProps: schema.items.properties || {},
427
+ respDescription: schema.items.description || '',
428
+ }
397
429
  } else if (schema.type === 'object') {
398
- return {
399
- respProps: schema.properties || {},
400
- respDescription: schema.description || responseObj.description || '',
401
- opDescription,
402
- requestBody
403
- };
430
+ if(objectKey){
431
+ // if objectKey contains [*] print something
432
+ if (objectKey.includes('[*]')) {
433
+ // complex object key
434
+ console.log(`Complex Object Key : ${objectKey}`);
435
+ const parts = objectKey.split('[*]');
436
+ const complexObjectKey = parts[1].replace('.', '');
437
+ console.log(`Item of Interest : ${complexObjectKey}`);
438
+ const respProps = schema.properties.items.additionalProperties.properties[complexObjectKey].items.properties;
439
+ console.info(respProps);
440
+ const respDescription = schema.properties.items.additionalProperties.properties[complexObjectKey].items.description || schema.properties.items.description || '';
441
+ console.log(respDescription);
442
+ return {
443
+ respProps: respProps || {},
444
+ respDescription: respDescription,
445
+ };
446
+
447
+ } else {
448
+ // simple object key
449
+ console.log(`Simple Object Key : ${objectKey}`);
450
+ const simpleObjectKey = objectKey.replace('$.', '');
451
+ const respProps = schema.properties[simpleObjectKey].items.properties;
452
+ console.info(respProps);
453
+ const respDescription = schema.properties[simpleObjectKey].items.description || schema.description || '';
454
+ console.log(respDescription);
455
+ return {
456
+ respProps: respProps || {},
457
+ respDescription: respDescription,
458
+ };
459
+ }
460
+ } else {
461
+ return {
462
+ respProps: schema.properties || {},
463
+ respDescription: schema.description || '',
464
+ };
465
+ }
404
466
  } else {
405
- // For primitive types or when schema structure is unexpected
406
467
  return {
407
468
  respProps: {},
408
- respDescription: schema.description || responseObj.description || '',
409
- opDescription,
410
- requestBody
469
+ respDescription: '',
411
470
  };
412
471
  }
413
472
  }