@tim-smart/openapi-gen 0.4.4 → 0.4.6
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 +55 -39
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -34825,18 +34825,38 @@ var make64 = gen2(function* () {
|
|
|
34825
34825
|
const refStore = /* @__PURE__ */ new Map();
|
|
34826
34826
|
function cleanupSchema(schema) {
|
|
34827
34827
|
if ("type" in schema && Array.isArray(schema.type) && schema.type.includes("null")) {
|
|
34828
|
-
|
|
34829
|
-
schema
|
|
34828
|
+
const type2 = schema.type.filter((_) => _ !== "null");
|
|
34829
|
+
schema = {
|
|
34830
|
+
...schema,
|
|
34831
|
+
type: type2.length === 1 ? type2[0] : type2,
|
|
34832
|
+
nullable: true
|
|
34833
|
+
};
|
|
34830
34834
|
}
|
|
34831
34835
|
if ("type" in schema && "oneOf" in schema && Array.isArray(schema.oneOf) && schema.oneOf.length === 0) {
|
|
34832
|
-
|
|
34836
|
+
schema = omit3(schema, "oneOf");
|
|
34837
|
+
}
|
|
34838
|
+
if ("allOf" in schema && schema.allOf.length === 1 || "oneOf" in schema && schema.oneOf.length === 1 || "anyOf" in schema && schema.anyOf.length === 1) {
|
|
34839
|
+
if ("allOf" in schema) {
|
|
34840
|
+
const item = schema.allOf[0];
|
|
34841
|
+
schema = omit3(schema, "allOf");
|
|
34842
|
+
Object.assign(schema, item);
|
|
34843
|
+
} else if ("anyOf" in schema) {
|
|
34844
|
+
const item = schema.anyOf[0];
|
|
34845
|
+
schema = omit3(schema, "anyOf");
|
|
34846
|
+
Object.assign(schema, item);
|
|
34847
|
+
} else {
|
|
34848
|
+
const item = schema.oneOf[0];
|
|
34849
|
+
schema = omit3(schema, "oneOf");
|
|
34850
|
+
Object.assign(schema, item);
|
|
34851
|
+
}
|
|
34833
34852
|
}
|
|
34834
34853
|
return schema;
|
|
34835
34854
|
}
|
|
34836
34855
|
const addSchema = (name2, root2, context7, asStruct = false) => {
|
|
34837
|
-
cleanupSchema(root2);
|
|
34856
|
+
root2 = cleanupSchema(root2);
|
|
34838
34857
|
function addRefs(schema, childName, asStruct2 = true) {
|
|
34839
|
-
cleanupSchema(schema);
|
|
34858
|
+
schema = cleanupSchema(schema);
|
|
34859
|
+
const enumSuffix = childName?.endsWith("Enum") ? "" : "Enum";
|
|
34840
34860
|
if ("$ref" in schema) {
|
|
34841
34861
|
const resolved = resolveRef(schema, {
|
|
34842
34862
|
...root2,
|
|
@@ -34865,32 +34885,26 @@ var make64 = gen2(function* () {
|
|
|
34865
34885
|
addRefs(schema.items, void 0);
|
|
34866
34886
|
}
|
|
34867
34887
|
} else if ("allOf" in schema) {
|
|
34868
|
-
|
|
34869
|
-
|
|
34870
|
-
|
|
34871
|
-
|
|
34888
|
+
const resolved = resolveAllOf(schema, {
|
|
34889
|
+
...root2,
|
|
34890
|
+
...context7
|
|
34891
|
+
});
|
|
34892
|
+
if (childName !== void 0) {
|
|
34893
|
+
addRefs(resolved, childName + enumSuffix, asStruct2);
|
|
34894
|
+
store.set(childName, resolved);
|
|
34872
34895
|
} else {
|
|
34873
|
-
|
|
34874
|
-
...root2,
|
|
34875
|
-
...context7
|
|
34876
|
-
});
|
|
34877
|
-
if (childName !== void 0) {
|
|
34878
|
-
addRefs(resolved, childName + "Enum", asStruct2);
|
|
34879
|
-
store.set(childName, resolved);
|
|
34880
|
-
} else {
|
|
34881
|
-
addRefs(resolved, void 0, asStruct2);
|
|
34882
|
-
}
|
|
34896
|
+
addRefs(resolved, void 0, asStruct2);
|
|
34883
34897
|
}
|
|
34884
34898
|
} else if ("anyOf" in schema) {
|
|
34885
34899
|
schema.anyOf.forEach(
|
|
34886
|
-
(s) => addRefs(s, childName ? childName +
|
|
34900
|
+
(s) => addRefs(s, childName ? childName + enumSuffix : void 0)
|
|
34887
34901
|
);
|
|
34888
34902
|
} else if ("oneOf" in schema) {
|
|
34889
34903
|
schema.oneOf.forEach(
|
|
34890
|
-
(s) => addRefs(s, childName ? childName +
|
|
34904
|
+
(s) => addRefs(s, childName ? childName + enumSuffix : void 0)
|
|
34891
34905
|
);
|
|
34892
34906
|
} else if ("enum" in schema) {
|
|
34893
|
-
if (childName !== void 0) {
|
|
34907
|
+
if (childName !== void 0 && !("const" in schema)) {
|
|
34894
34908
|
store.set(childName, schema);
|
|
34895
34909
|
enums.add(childName);
|
|
34896
34910
|
}
|
|
@@ -34936,7 +34950,7 @@ var make64 = gen2(function* () {
|
|
|
34936
34950
|
if ("$ref" in raw) {
|
|
34937
34951
|
return refStore.get(raw.$ref) ?? raw;
|
|
34938
34952
|
}
|
|
34939
|
-
return raw;
|
|
34953
|
+
return cleanupSchema(raw);
|
|
34940
34954
|
};
|
|
34941
34955
|
const flattenAllOf = (schema) => {
|
|
34942
34956
|
if ("allOf" in schema) {
|
|
@@ -34954,6 +34968,7 @@ var make64 = gen2(function* () {
|
|
|
34954
34968
|
};
|
|
34955
34969
|
const transformer = yield* JsonSchemaTransformer;
|
|
34956
34970
|
const toSource = (importName, schema, currentIdentifier, topLevel = false) => {
|
|
34971
|
+
schema = cleanupSchema(schema);
|
|
34957
34972
|
if ("properties" in schema) {
|
|
34958
34973
|
const obj = schema;
|
|
34959
34974
|
const required2 = obj.required ?? [];
|
|
@@ -34961,6 +34976,7 @@ var make64 = gen2(function* () {
|
|
|
34961
34976
|
Object.entries(obj.properties ?? {}),
|
|
34962
34977
|
filterMap2(([key, schema2]) => {
|
|
34963
34978
|
const fullSchema = getSchema(schema2);
|
|
34979
|
+
schema2 = cleanupSchema(schema2);
|
|
34964
34980
|
const isOptional = !required2.includes(key);
|
|
34965
34981
|
const [enumNullable, filteredSchema] = filterNullable(fullSchema);
|
|
34966
34982
|
return toSource(
|
|
@@ -34990,11 +35006,22 @@ var make64 = gen2(function* () {
|
|
|
34990
35006
|
return some2(transformer.onNull({ importName }));
|
|
34991
35007
|
} else if ("type" in schema && schema.type === "object") {
|
|
34992
35008
|
return some2(transformer.onRecord({ importName }));
|
|
35009
|
+
} else if ("const" in schema) {
|
|
35010
|
+
return some2(
|
|
35011
|
+
transformer.onEnum({
|
|
35012
|
+
importName,
|
|
35013
|
+
items: [JSON.stringify(schema.const)]
|
|
35014
|
+
})
|
|
35015
|
+
);
|
|
34993
35016
|
} else if ("enum" in schema) {
|
|
34994
35017
|
if (!topLevel && enums.has(currentIdentifier)) {
|
|
34995
35018
|
return some2(
|
|
34996
35019
|
transformer.onRef({ importName, name: currentIdentifier })
|
|
34997
35020
|
);
|
|
35021
|
+
} else if (!topLevel && enums.has(currentIdentifier + "Enum")) {
|
|
35022
|
+
return some2(
|
|
35023
|
+
transformer.onRef({ importName, name: currentIdentifier + "Enum" })
|
|
35024
|
+
);
|
|
34998
35025
|
}
|
|
34999
35026
|
const items = schema.enum.map((_) => JSON.stringify(_));
|
|
35000
35027
|
return some2(
|
|
@@ -35025,13 +35052,6 @@ var make64 = gen2(function* () {
|
|
|
35025
35052
|
const sources = schema.allOf;
|
|
35026
35053
|
if (sources.length === 0) {
|
|
35027
35054
|
return none2();
|
|
35028
|
-
} else if (sources.length === 1) {
|
|
35029
|
-
return toSource(
|
|
35030
|
-
importName,
|
|
35031
|
-
sources[0],
|
|
35032
|
-
currentIdentifier + "Enum",
|
|
35033
|
-
topLevel
|
|
35034
|
-
);
|
|
35035
35055
|
}
|
|
35036
35056
|
const flattened2 = flattenAllOf(schema);
|
|
35037
35057
|
return toSource(
|
|
@@ -35068,16 +35088,12 @@ var make64 = gen2(function* () {
|
|
|
35068
35088
|
)
|
|
35069
35089
|
)
|
|
35070
35090
|
);
|
|
35071
|
-
if (items.length === 0)
|
|
35072
|
-
|
|
35091
|
+
if (items.length === 0) {
|
|
35092
|
+
return none2();
|
|
35093
|
+
} else if (items.length === 1) {
|
|
35094
|
+
return some2(items[0].source);
|
|
35095
|
+
}
|
|
35073
35096
|
return some2(transformer.onUnion({ importName, items, topLevel }));
|
|
35074
|
-
} else if ("const" in schema) {
|
|
35075
|
-
return some2(
|
|
35076
|
-
transformer.onEnum({
|
|
35077
|
-
importName,
|
|
35078
|
-
items: [JSON.stringify(schema.const)]
|
|
35079
|
-
})
|
|
35080
|
-
);
|
|
35081
35097
|
} else if ("type" in schema && schema.type) {
|
|
35082
35098
|
switch (schema.type) {
|
|
35083
35099
|
case "string": {
|