swgto-ts 3.2.0 → 3.3.0

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.
@@ -553,7 +553,7 @@ function formatDocLines(lines) {
553
553
  }
554
554
  return ["/**", ...lines.map((line) => ` * ${line}`), " */"].join("\n");
555
555
  }
556
- function buildSchemaDoc(schema) {
556
+ function buildSchemaDocLines(schema) {
557
557
  const lines = [];
558
558
  if (schema?.description) {
559
559
  lines.push(schema.description);
@@ -561,7 +561,10 @@ function buildSchemaDoc(schema) {
561
561
  if (schema && schema.example !== void 0) {
562
562
  lines.push(`@example ${JSON.stringify(schema.example)}`);
563
563
  }
564
- return formatDocLines(lines);
564
+ return lines;
565
+ }
566
+ function buildSchemaDoc(schema) {
567
+ return formatDocLines(buildSchemaDocLines(schema));
565
568
  }
566
569
  function jsdocToInline(doc, indent) {
567
570
  return doc.split("\n").filter((line) => {
@@ -616,6 +619,24 @@ function renderComponentSchemas(document) {
616
619
  function toJSDocType(typeText) {
617
620
  return typeText.replace(/;\s*/g, ", ").replace(/,\s*\}/g, " }");
618
621
  }
622
+ function renderJsTypedef(name, schema) {
623
+ const typed = schema;
624
+ const properties = Object.entries(typed?.properties ?? {});
625
+ if (properties.length && (typed?.type === "object" || typed?.properties)) {
626
+ const requiredSet = new Set(typed?.required ?? []);
627
+ const lines = [...buildSchemaDocLines(typed), `@typedef {Object} ${name}`];
628
+ for (const [key, value] of properties) {
629
+ const propName = toTypePropertyName(key);
630
+ const fieldDoc = buildSchemaDocLines(value).join(" ");
631
+ const field = requiredSet.has(key) ? propName : `[${propName}]`;
632
+ lines.push(`@property {${toJSDocType(schemaToTs(value))}} ${field}${fieldDoc ? ` - ${fieldDoc}` : ""}`);
633
+ }
634
+ return formatDocLines(lines);
635
+ }
636
+ const doc = buildSchemaDocLines(typed);
637
+ const type = toJSDocType(schemaToTs(schema));
638
+ return doc.length ? formatDocLines([...doc, `@typedef {${type}} ${name}`]) : `/** @typedef {${type}} ${name} */`;
639
+ }
619
640
  function generateTypesFile(documentMap, operations, config) {
620
641
  if (config.outputType === "js") {
621
642
  const parts2 = [
@@ -627,12 +648,12 @@ function generateTypesFile(documentMap, operations, config) {
627
648
  const moduleName = config.moduleName?.(docUrl) ?? "services";
628
649
  parts2.push(`// Types from ${moduleName}`);
629
650
  for (const [name, schema] of Object.entries(document.components?.schemas ?? {})) {
630
- parts2.push(`/** @typedef {${toJSDocType(schemaToTs(schema))}} ${sanitizeSchemaTypeName(name)} */`);
651
+ parts2.push(renderJsTypedef(sanitizeSchemaTypeName(name), schema));
631
652
  }
632
653
  }
633
654
  for (const operation of operations) {
634
655
  if (operation.responseTypeName) {
635
- parts2.push(`/** @typedef {${toJSDocType(schemaToTs(operation.responseSchema))}} ${operation.responseTypeName} */`);
656
+ parts2.push(renderJsTypedef(operation.responseTypeName, operation.responseSchema));
636
657
  }
637
658
  }
638
659
  parts2.push("export {};");
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  generateFromConfig
4
- } from "./chunk-4K4VW2PJ.js";
4
+ } from "./chunk-5YE6QJXH.js";
5
5
  import "./chunk-EAGONRXV.js";
6
6
 
7
7
  // src/cli.ts
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  generateFromConfig
3
- } from "./chunk-4K4VW2PJ.js";
3
+ } from "./chunk-5YE6QJXH.js";
4
4
  import "./chunk-EAGONRXV.js";
5
5
  export {
6
6
  generateFromConfig
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swgto-ts",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "Generate API request files from OpenAPI 3.x documents.",
5
5
  "license": "MIT",
6
6
  "type": "module",