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