@tim-smart/openapi-gen 0.4.3 → 0.4.5
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 +74 -52
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -19351,6 +19351,7 @@ var TaggedError = (tag4) => {
|
|
|
19351
19351
|
};
|
|
19352
19352
|
|
|
19353
19353
|
// node_modules/.pnpm/effect@3.15.2/node_modules/effect/dist/esm/String.js
|
|
19354
|
+
var isString2 = isString;
|
|
19354
19355
|
var toUpperCase = (self) => self.toUpperCase();
|
|
19355
19356
|
var capitalize = (self) => {
|
|
19356
19357
|
if (self.length === 0) return self;
|
|
@@ -34802,6 +34803,19 @@ var camelize = (self) => {
|
|
|
34802
34803
|
return str;
|
|
34803
34804
|
};
|
|
34804
34805
|
var identifier2 = (operationId) => capitalize(camelize(operationId));
|
|
34806
|
+
var nonEmptyString3 = flow(
|
|
34807
|
+
fromNullable,
|
|
34808
|
+
filter(isString2),
|
|
34809
|
+
map2(trim),
|
|
34810
|
+
filter(isNonEmpty5)
|
|
34811
|
+
);
|
|
34812
|
+
var toComment = match2({
|
|
34813
|
+
onNone: () => "",
|
|
34814
|
+
onSome: (description) => `/**
|
|
34815
|
+
* ${description.split("\n").join("\n* ")}
|
|
34816
|
+
*/
|
|
34817
|
+
`
|
|
34818
|
+
});
|
|
34805
34819
|
|
|
34806
34820
|
// src/JsonSchemaGen.ts
|
|
34807
34821
|
var make64 = gen2(function* () {
|
|
@@ -34811,18 +34825,37 @@ var make64 = gen2(function* () {
|
|
|
34811
34825
|
const refStore = /* @__PURE__ */ new Map();
|
|
34812
34826
|
function cleanupSchema(schema) {
|
|
34813
34827
|
if ("type" in schema && Array.isArray(schema.type) && schema.type.includes("null")) {
|
|
34814
|
-
schema
|
|
34815
|
-
|
|
34828
|
+
schema = {
|
|
34829
|
+
...schema,
|
|
34830
|
+
type: schema.type.filter((_) => _ !== "null"),
|
|
34831
|
+
nullable: true
|
|
34832
|
+
};
|
|
34816
34833
|
}
|
|
34817
34834
|
if ("type" in schema && "oneOf" in schema && Array.isArray(schema.oneOf) && schema.oneOf.length === 0) {
|
|
34818
|
-
|
|
34835
|
+
schema = omit3(schema, "oneOf");
|
|
34836
|
+
}
|
|
34837
|
+
if ("allOf" in schema && schema.allOf.length === 1 || "oneOf" in schema && schema.oneOf.length === 1 || "anyOf" in schema && schema.anyOf.length === 1) {
|
|
34838
|
+
if ("allOf" in schema) {
|
|
34839
|
+
const item = schema.allOf[0];
|
|
34840
|
+
schema = omit3(schema, "allOf");
|
|
34841
|
+
Object.assign(schema, item);
|
|
34842
|
+
} else if ("anyOf" in schema) {
|
|
34843
|
+
const item = schema.anyOf[0];
|
|
34844
|
+
schema = omit3(schema, "anyOf");
|
|
34845
|
+
Object.assign(schema, item);
|
|
34846
|
+
} else {
|
|
34847
|
+
const item = schema.oneOf[0];
|
|
34848
|
+
schema = omit3(schema, "oneOf");
|
|
34849
|
+
Object.assign(schema, item);
|
|
34850
|
+
}
|
|
34819
34851
|
}
|
|
34820
34852
|
return schema;
|
|
34821
34853
|
}
|
|
34822
34854
|
const addSchema = (name2, root2, context7, asStruct = false) => {
|
|
34823
|
-
cleanupSchema(root2);
|
|
34855
|
+
root2 = cleanupSchema(root2);
|
|
34824
34856
|
function addRefs(schema, childName, asStruct2 = true) {
|
|
34825
|
-
cleanupSchema(schema);
|
|
34857
|
+
schema = cleanupSchema(schema);
|
|
34858
|
+
const enumSuffix = childName?.endsWith("Enum") ? "" : "Enum";
|
|
34826
34859
|
if ("$ref" in schema) {
|
|
34827
34860
|
const resolved = resolveRef(schema, {
|
|
34828
34861
|
...root2,
|
|
@@ -34851,32 +34884,26 @@ var make64 = gen2(function* () {
|
|
|
34851
34884
|
addRefs(schema.items, void 0);
|
|
34852
34885
|
}
|
|
34853
34886
|
} else if ("allOf" in schema) {
|
|
34854
|
-
|
|
34855
|
-
|
|
34856
|
-
|
|
34857
|
-
|
|
34887
|
+
const resolved = resolveAllOf(schema, {
|
|
34888
|
+
...root2,
|
|
34889
|
+
...context7
|
|
34890
|
+
});
|
|
34891
|
+
if (childName !== void 0) {
|
|
34892
|
+
addRefs(resolved, childName + enumSuffix, asStruct2);
|
|
34893
|
+
store.set(childName, resolved);
|
|
34858
34894
|
} else {
|
|
34859
|
-
|
|
34860
|
-
...root2,
|
|
34861
|
-
...context7
|
|
34862
|
-
});
|
|
34863
|
-
if (childName !== void 0) {
|
|
34864
|
-
addRefs(resolved, childName + "Enum", asStruct2);
|
|
34865
|
-
store.set(childName, resolved);
|
|
34866
|
-
} else {
|
|
34867
|
-
addRefs(resolved, void 0, asStruct2);
|
|
34868
|
-
}
|
|
34895
|
+
addRefs(resolved, void 0, asStruct2);
|
|
34869
34896
|
}
|
|
34870
34897
|
} else if ("anyOf" in schema) {
|
|
34871
34898
|
schema.anyOf.forEach(
|
|
34872
|
-
(s) => addRefs(s, childName ? childName +
|
|
34899
|
+
(s) => addRefs(s, childName ? childName + enumSuffix : void 0)
|
|
34873
34900
|
);
|
|
34874
34901
|
} else if ("oneOf" in schema) {
|
|
34875
34902
|
schema.oneOf.forEach(
|
|
34876
|
-
(s) => addRefs(s, childName ? childName +
|
|
34903
|
+
(s) => addRefs(s, childName ? childName + enumSuffix : void 0)
|
|
34877
34904
|
);
|
|
34878
34905
|
} else if ("enum" in schema) {
|
|
34879
|
-
if (childName !== void 0) {
|
|
34906
|
+
if (childName !== void 0 && !("const" in schema)) {
|
|
34880
34907
|
store.set(childName, schema);
|
|
34881
34908
|
enums.add(childName);
|
|
34882
34909
|
}
|
|
@@ -34940,6 +34967,10 @@ var make64 = gen2(function* () {
|
|
|
34940
34967
|
};
|
|
34941
34968
|
const transformer = yield* JsonSchemaTransformer;
|
|
34942
34969
|
const toSource = (importName, schema, currentIdentifier, topLevel = false) => {
|
|
34970
|
+
schema = cleanupSchema(schema);
|
|
34971
|
+
if (currentIdentifier.startsWith("FunctionCall")) {
|
|
34972
|
+
console.error(schema, currentIdentifier);
|
|
34973
|
+
}
|
|
34943
34974
|
if ("properties" in schema) {
|
|
34944
34975
|
const obj = schema;
|
|
34945
34976
|
const required2 = obj.required ?? [];
|
|
@@ -34976,11 +35007,22 @@ var make64 = gen2(function* () {
|
|
|
34976
35007
|
return some2(transformer.onNull({ importName }));
|
|
34977
35008
|
} else if ("type" in schema && schema.type === "object") {
|
|
34978
35009
|
return some2(transformer.onRecord({ importName }));
|
|
35010
|
+
} else if ("const" in schema) {
|
|
35011
|
+
return some2(
|
|
35012
|
+
transformer.onEnum({
|
|
35013
|
+
importName,
|
|
35014
|
+
items: [JSON.stringify(schema.const)]
|
|
35015
|
+
})
|
|
35016
|
+
);
|
|
34979
35017
|
} else if ("enum" in schema) {
|
|
34980
35018
|
if (!topLevel && enums.has(currentIdentifier)) {
|
|
34981
35019
|
return some2(
|
|
34982
35020
|
transformer.onRef({ importName, name: currentIdentifier })
|
|
34983
35021
|
);
|
|
35022
|
+
} else if (!topLevel && enums.has(currentIdentifier + "Enum")) {
|
|
35023
|
+
return some2(
|
|
35024
|
+
transformer.onRef({ importName, name: currentIdentifier + "Enum" })
|
|
35025
|
+
);
|
|
34984
35026
|
}
|
|
34985
35027
|
const items = schema.enum.map((_) => JSON.stringify(_));
|
|
34986
35028
|
return some2(
|
|
@@ -35011,13 +35053,6 @@ var make64 = gen2(function* () {
|
|
|
35011
35053
|
const sources = schema.allOf;
|
|
35012
35054
|
if (sources.length === 0) {
|
|
35013
35055
|
return none2();
|
|
35014
|
-
} else if (sources.length === 1) {
|
|
35015
|
-
return toSource(
|
|
35016
|
-
importName,
|
|
35017
|
-
sources[0],
|
|
35018
|
-
currentIdentifier + "Enum",
|
|
35019
|
-
topLevel
|
|
35020
|
-
);
|
|
35021
35056
|
}
|
|
35022
35057
|
const flattened2 = flattenAllOf(schema);
|
|
35023
35058
|
return toSource(
|
|
@@ -35054,16 +35089,12 @@ var make64 = gen2(function* () {
|
|
|
35054
35089
|
)
|
|
35055
35090
|
)
|
|
35056
35091
|
);
|
|
35057
|
-
if (items.length === 0)
|
|
35058
|
-
|
|
35092
|
+
if (items.length === 0) {
|
|
35093
|
+
return none2();
|
|
35094
|
+
} else if (items.length === 1) {
|
|
35095
|
+
return some2(items[0].source);
|
|
35096
|
+
}
|
|
35059
35097
|
return some2(transformer.onUnion({ importName, items, topLevel }));
|
|
35060
|
-
} else if ("const" in schema) {
|
|
35061
|
-
return some2(
|
|
35062
|
-
transformer.onEnum({
|
|
35063
|
-
importName,
|
|
35064
|
-
items: [JSON.stringify(schema.const)]
|
|
35065
|
-
})
|
|
35066
|
-
);
|
|
35067
35098
|
} else if ("type" in schema && schema.type) {
|
|
35068
35099
|
switch (schema.type) {
|
|
35069
35100
|
case "string": {
|
|
@@ -35300,18 +35331,6 @@ export type ${name2} = (typeof ${name2})[keyof typeof ${name2}];` : `${toComment
|
|
|
35300
35331
|
}
|
|
35301
35332
|
})
|
|
35302
35333
|
);
|
|
35303
|
-
var nonEmptyString3 = flow(
|
|
35304
|
-
fromNullable,
|
|
35305
|
-
map2(trim),
|
|
35306
|
-
filter(isNonEmpty5)
|
|
35307
|
-
);
|
|
35308
|
-
var toComment = match2({
|
|
35309
|
-
onNone: () => "",
|
|
35310
|
-
onSome: (description) => `/**
|
|
35311
|
-
* ${description.split("\n").join("\n* ")}
|
|
35312
|
-
*/
|
|
35313
|
-
`
|
|
35314
|
-
});
|
|
35315
35334
|
function mergeSchemas(self, other) {
|
|
35316
35335
|
if ("properties" in self && "properties" in other) {
|
|
35317
35336
|
return {
|
|
@@ -35460,6 +35479,9 @@ var make65 = gen2(function* () {
|
|
|
35460
35479
|
const op = {
|
|
35461
35480
|
id: camelize(operation.operationId),
|
|
35462
35481
|
method,
|
|
35482
|
+
description: nonEmptyString3(operation.description).pipe(
|
|
35483
|
+
orElse(() => nonEmptyString3(operation.summary))
|
|
35484
|
+
),
|
|
35463
35485
|
pathIds,
|
|
35464
35486
|
pathTemplate,
|
|
35465
35487
|
urlParams: [],
|
|
@@ -35631,7 +35653,7 @@ ${clientErrorSource(name2)}`;
|
|
|
35631
35653
|
)
|
|
35632
35654
|
);
|
|
35633
35655
|
}
|
|
35634
|
-
return
|
|
35656
|
+
return `${toComment(operation.description)}readonly "${operation.id}": (${args2.join(", ")}) => Effect.Effect<${success}, ${errors.join(" | ")}>`;
|
|
35635
35657
|
};
|
|
35636
35658
|
const operationsToImpl = (name2, operations) => `export const make = (
|
|
35637
35659
|
httpClient: HttpClient.HttpClient,
|
|
@@ -35762,7 +35784,7 @@ ${clientErrorSource(name2)}`;
|
|
|
35762
35784
|
errors.push(`${name2}Error<"${schema}", ${schema}>`);
|
|
35763
35785
|
}
|
|
35764
35786
|
}
|
|
35765
|
-
return
|
|
35787
|
+
return `${toComment(operation.description)}readonly "${operation.id}": (${args2.join(", ")}) => Effect.Effect<${success}, ${errors.join(" | ")}>`;
|
|
35766
35788
|
};
|
|
35767
35789
|
const operationsToImpl = (name2, operations) => `export const make = (
|
|
35768
35790
|
httpClient: HttpClient.HttpClient,
|