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.
- package/dist/{chunk-4K4VW2PJ.js → chunk-5YE6QJXH.js} +25 -4
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -553,7 +553,7 @@ function formatDocLines(lines) {
|
|
|
553
553
|
}
|
|
554
554
|
return ["/**", ...lines.map((line) => ` * ${line}`), " */"].join("\n");
|
|
555
555
|
}
|
|
556
|
-
function
|
|
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
|
|
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(
|
|
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(
|
|
656
|
+
parts2.push(renderJsTypedef(operation.responseTypeName, operation.responseSchema));
|
|
636
657
|
}
|
|
637
658
|
}
|
|
638
659
|
parts2.push("export {};");
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED