@tim-smart/openapi-gen 0.3.1 → 0.3.2
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/main.js +34 -17
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -29383,9 +29383,10 @@ var identifier = (operationId) => capitalize(camelize(operationId));
|
|
|
29383
29383
|
var make65 = gen2(function* () {
|
|
29384
29384
|
const store = /* @__PURE__ */ new Map();
|
|
29385
29385
|
const classes = /* @__PURE__ */ new Set();
|
|
29386
|
+
const enums = /* @__PURE__ */ new Set();
|
|
29386
29387
|
const refStore = /* @__PURE__ */ new Map();
|
|
29387
29388
|
const addSchema = (name, root2, context7, asStruct = false) => {
|
|
29388
|
-
function addRefs(schema, asStruct2 = true) {
|
|
29389
|
+
function addRefs(schema, childName, asStruct2 = true) {
|
|
29389
29390
|
if ("$ref" in schema) {
|
|
29390
29391
|
if (!schema.$ref.startsWith("#")) {
|
|
29391
29392
|
return;
|
|
@@ -29404,32 +29405,39 @@ var make65 = gen2(function* () {
|
|
|
29404
29405
|
current = current[key];
|
|
29405
29406
|
}
|
|
29406
29407
|
refStore.set(schema.$ref, current);
|
|
29407
|
-
addRefs(current);
|
|
29408
|
+
addRefs(current, "properties" in current ? name2 : void 0);
|
|
29408
29409
|
store.set(name2, current);
|
|
29409
29410
|
if (!asStruct2) {
|
|
29410
29411
|
classes.add(name2);
|
|
29411
29412
|
}
|
|
29412
29413
|
} else if ("properties" in schema) {
|
|
29413
|
-
Object.
|
|
29414
|
+
Object.entries(schema.properties).forEach(
|
|
29415
|
+
([name2, s]) => addRefs(s, childName ? childName + identifier(name2) : void 0)
|
|
29416
|
+
);
|
|
29414
29417
|
} else if ("type" in schema && schema.type === "array") {
|
|
29415
29418
|
if (Array.isArray(schema.items)) {
|
|
29416
|
-
schema.items.forEach((s) => addRefs(s));
|
|
29419
|
+
schema.items.forEach((s) => addRefs(s, childName));
|
|
29417
29420
|
} else if (schema.items) {
|
|
29418
|
-
addRefs(schema.items);
|
|
29421
|
+
addRefs(schema.items, childName);
|
|
29419
29422
|
}
|
|
29420
29423
|
} else if ("allOf" in schema) {
|
|
29421
|
-
schema.allOf.forEach((s) => addRefs(s));
|
|
29424
|
+
schema.allOf.forEach((s) => addRefs(s, childName));
|
|
29422
29425
|
} else if ("anyOf" in schema) {
|
|
29423
|
-
schema.anyOf.forEach((s) => addRefs(s));
|
|
29426
|
+
schema.anyOf.forEach((s) => addRefs(s, childName));
|
|
29424
29427
|
} else if ("oneOf" in schema) {
|
|
29425
|
-
schema.oneOf.forEach((s) => addRefs(s));
|
|
29428
|
+
schema.oneOf.forEach((s) => addRefs(s, childName));
|
|
29429
|
+
} else if ("enum" in schema) {
|
|
29430
|
+
if (childName !== void 0) {
|
|
29431
|
+
store.set(childName, schema);
|
|
29432
|
+
enums.add(childName);
|
|
29433
|
+
}
|
|
29426
29434
|
}
|
|
29427
29435
|
}
|
|
29428
29436
|
if ("$ref" in root2) {
|
|
29429
|
-
addRefs(root2, false);
|
|
29437
|
+
addRefs(root2, void 0, false);
|
|
29430
29438
|
return identifier(root2.$ref.split("/").pop());
|
|
29431
29439
|
} else {
|
|
29432
|
-
addRefs(root2);
|
|
29440
|
+
addRefs(root2, "properties" in root2 ? name : void 0);
|
|
29433
29441
|
store.set(name, root2);
|
|
29434
29442
|
if (!asStruct) {
|
|
29435
29443
|
classes.add(name);
|
|
@@ -29439,7 +29447,8 @@ var make65 = gen2(function* () {
|
|
|
29439
29447
|
};
|
|
29440
29448
|
const topLevelSource = (S, name, schema) => {
|
|
29441
29449
|
const isClass = classes.has(name);
|
|
29442
|
-
|
|
29450
|
+
const isEnum = enums.has(name);
|
|
29451
|
+
return toSource(S, schema, name, isClass || isEnum).pipe(
|
|
29443
29452
|
map((source) => {
|
|
29444
29453
|
const isObject2 = "properties" in schema;
|
|
29445
29454
|
if (!isObject2 || !isClass) {
|
|
@@ -29449,7 +29458,7 @@ var make65 = gen2(function* () {
|
|
|
29449
29458
|
})
|
|
29450
29459
|
);
|
|
29451
29460
|
};
|
|
29452
|
-
const toSource = (S, schema, topLevel = false) => {
|
|
29461
|
+
const toSource = (S, schema, currentIdentifier, topLevel = false) => {
|
|
29453
29462
|
if ("properties" in schema) {
|
|
29454
29463
|
const obj = schema;
|
|
29455
29464
|
const required2 = obj.required ?? [];
|
|
@@ -29458,7 +29467,7 @@ var make65 = gen2(function* () {
|
|
|
29458
29467
|
filterMap2(([key, schema2]) => {
|
|
29459
29468
|
const fullSchema = "$ref" in schema2 ? refStore.get(schema2.$ref) : schema2;
|
|
29460
29469
|
const isOptional = !required2.includes(key);
|
|
29461
|
-
return toSource(S, schema2).pipe(
|
|
29470
|
+
return toSource(S, schema2, currentIdentifier + identifier(key)).pipe(
|
|
29462
29471
|
map(
|
|
29463
29472
|
applyAnnotations(S, {
|
|
29464
29473
|
isOptional,
|
|
@@ -29483,6 +29492,9 @@ var make65 = gen2(function* () {
|
|
|
29483
29492
|
`${S}.Record({ key: ${S}.String, value: ${S}.Unknown })`
|
|
29484
29493
|
);
|
|
29485
29494
|
} else if ("enum" in schema) {
|
|
29495
|
+
if (!topLevel && enums.has(currentIdentifier)) {
|
|
29496
|
+
return some2(currentIdentifier);
|
|
29497
|
+
}
|
|
29486
29498
|
const items = schema.enum.map((_) => JSON.stringify(_)).join(", ");
|
|
29487
29499
|
return some2(`${S}.Literal(${items})`);
|
|
29488
29500
|
} else if ("type" in schema) {
|
|
@@ -29535,7 +29547,7 @@ var make65 = gen2(function* () {
|
|
|
29535
29547
|
if ("maxItems" in schema) {
|
|
29536
29548
|
modifiers.push(`${S}.maxItems(${schema.maxItems})`);
|
|
29537
29549
|
}
|
|
29538
|
-
return toSource(S, itemsSchema(schema.items)).pipe(
|
|
29550
|
+
return toSource(S, itemsSchema(schema.items), currentIdentifier).pipe(
|
|
29539
29551
|
map(
|
|
29540
29552
|
(source) => `${S}.${nonEmpty ? "NonEmpty" : ""}Array(${source})${pipeSource(modifiers)}`
|
|
29541
29553
|
)
|
|
@@ -29549,11 +29561,16 @@ var make65 = gen2(function* () {
|
|
|
29549
29561
|
const name = identifier(schema.$ref.split("/").pop());
|
|
29550
29562
|
return some2(name);
|
|
29551
29563
|
} else if ("properties" in schema) {
|
|
29552
|
-
return toSource(
|
|
29564
|
+
return toSource(
|
|
29565
|
+
S,
|
|
29566
|
+
{ type: "object", ...schema },
|
|
29567
|
+
currentIdentifier,
|
|
29568
|
+
topLevel
|
|
29569
|
+
);
|
|
29553
29570
|
} else if ("allOf" in schema) {
|
|
29554
29571
|
const sources = pipe(
|
|
29555
29572
|
schema.allOf,
|
|
29556
|
-
filterMap2((_) => toSource(S, _))
|
|
29573
|
+
filterMap2((_) => toSource(S, _, currentIdentifier))
|
|
29557
29574
|
);
|
|
29558
29575
|
if (sources.length === 0) {
|
|
29559
29576
|
return none2();
|
|
@@ -29569,7 +29586,7 @@ var make65 = gen2(function* () {
|
|
|
29569
29586
|
} else if ("anyOf" in schema || "oneOf" in schema) {
|
|
29570
29587
|
const sources = pipe(
|
|
29571
29588
|
"anyOf" in schema ? schema.anyOf : schema.oneOf,
|
|
29572
|
-
filterMap2((_) => toSource(S, _))
|
|
29589
|
+
filterMap2((_) => toSource(S, _, currentIdentifier))
|
|
29573
29590
|
);
|
|
29574
29591
|
if (sources.length === 0) return none2();
|
|
29575
29592
|
else if (sources.length === 1) return some2(sources[0]);
|