@tim-smart/openapi-gen 0.4.13 → 0.4.14
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 +77 -17
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -34816,6 +34816,24 @@ var toComment = match2({
|
|
|
34816
34816
|
*/
|
|
34817
34817
|
`
|
|
34818
34818
|
});
|
|
34819
|
+
var decodeRefTokens = (ref) => {
|
|
34820
|
+
if (!ref) return [];
|
|
34821
|
+
let fragment = ref.startsWith("#") ? ref.slice(1) : ref;
|
|
34822
|
+
if (fragment.startsWith("/")) fragment = fragment.slice(1);
|
|
34823
|
+
if (fragment.length === 0) return [];
|
|
34824
|
+
return fragment.split("/").map((raw) => {
|
|
34825
|
+
let token = raw;
|
|
34826
|
+
try {
|
|
34827
|
+
token = decodeURIComponent(raw);
|
|
34828
|
+
} catch {
|
|
34829
|
+
}
|
|
34830
|
+
return token.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
34831
|
+
});
|
|
34832
|
+
};
|
|
34833
|
+
var refLastToken = (ref) => {
|
|
34834
|
+
const tokens = decodeRefTokens(ref);
|
|
34835
|
+
return tokens.length > 0 ? tokens[tokens.length - 1] : ref;
|
|
34836
|
+
};
|
|
34819
34837
|
|
|
34820
34838
|
// src/JsonSchemaGen.ts
|
|
34821
34839
|
var make64 = gen2(function* () {
|
|
@@ -34824,6 +34842,12 @@ var make64 = gen2(function* () {
|
|
|
34824
34842
|
const enums = /* @__PURE__ */ new Set();
|
|
34825
34843
|
const refStore = /* @__PURE__ */ new Map();
|
|
34826
34844
|
function cleanupSchema(schema) {
|
|
34845
|
+
if (typeof schema === "boolean") {
|
|
34846
|
+
return schema;
|
|
34847
|
+
}
|
|
34848
|
+
if (typeof schema !== "object" || schema === null) {
|
|
34849
|
+
return schema;
|
|
34850
|
+
}
|
|
34827
34851
|
if ("type" in schema && Array.isArray(schema.type) && schema.type.includes("null")) {
|
|
34828
34852
|
const type2 = schema.type.filter((_) => _ !== "null");
|
|
34829
34853
|
schema = {
|
|
@@ -34838,8 +34862,8 @@ var make64 = gen2(function* () {
|
|
|
34838
34862
|
if ("allOf" in schema && schema.allOf.length === 1 || "oneOf" in schema && schema.oneOf.length === 1 || "anyOf" in schema && schema.anyOf.length === 1) {
|
|
34839
34863
|
if ("allOf" in schema) {
|
|
34840
34864
|
const item = schema.allOf[0];
|
|
34841
|
-
|
|
34842
|
-
|
|
34865
|
+
const baseSchema = omit3(schema, "allOf");
|
|
34866
|
+
schema = mergeSchemas(baseSchema, item);
|
|
34843
34867
|
} else if ("anyOf" in schema) {
|
|
34844
34868
|
const item = schema.anyOf[0];
|
|
34845
34869
|
schema = omit3(schema, "anyOf");
|
|
@@ -34857,6 +34881,12 @@ var make64 = gen2(function* () {
|
|
|
34857
34881
|
root2 = cleanupSchema(root2);
|
|
34858
34882
|
function addRefs(schema, childName, asStruct2 = true) {
|
|
34859
34883
|
schema = cleanupSchema(schema);
|
|
34884
|
+
if (typeof schema === "boolean") {
|
|
34885
|
+
return;
|
|
34886
|
+
}
|
|
34887
|
+
if (typeof schema !== "object" || schema === null) {
|
|
34888
|
+
return;
|
|
34889
|
+
}
|
|
34860
34890
|
const enumSuffix = childName?.endsWith("Enum") ? "" : "Enum";
|
|
34861
34891
|
if ("$ref" in schema) {
|
|
34862
34892
|
if (seenRefs.has(schema.$ref)) {
|
|
@@ -34877,7 +34907,7 @@ var make64 = gen2(function* () {
|
|
|
34877
34907
|
addRefs(resolved.schema, resolved.name);
|
|
34878
34908
|
store.set(resolved.name, resolved.schema);
|
|
34879
34909
|
classes.add(resolved.name);
|
|
34880
|
-
} else if ("properties" in schema) {
|
|
34910
|
+
} else if ("properties" in schema && schema.properties) {
|
|
34881
34911
|
Object.entries(schema.properties).forEach(
|
|
34882
34912
|
([name3, s]) => addRefs(s, childName ? childName + identifier2(name3) : void 0)
|
|
34883
34913
|
);
|
|
@@ -34915,10 +34945,11 @@ var make64 = gen2(function* () {
|
|
|
34915
34945
|
}
|
|
34916
34946
|
if ("$ref" in root2) {
|
|
34917
34947
|
addRefs(root2, void 0, false);
|
|
34918
|
-
return identifier2(root2.$ref
|
|
34948
|
+
return identifier2(refLastToken(root2.$ref));
|
|
34919
34949
|
} else {
|
|
34920
34950
|
addRefs(root2, "properties" in root2 ? name2 : void 0);
|
|
34921
|
-
|
|
34951
|
+
const resolvedRoot = "allOf" in root2 ? resolveAllOf(root2, { ...root2, ...context7 }) : root2;
|
|
34952
|
+
store.set(name2, resolvedRoot);
|
|
34922
34953
|
if (!asStruct) {
|
|
34923
34954
|
classes.add(name2);
|
|
34924
34955
|
}
|
|
@@ -34935,9 +34966,12 @@ var make64 = gen2(function* () {
|
|
|
34935
34966
|
isClass,
|
|
34936
34967
|
isEnum
|
|
34937
34968
|
});
|
|
34938
|
-
return toSource(
|
|
34939
|
-
|
|
34940
|
-
|
|
34969
|
+
return toSource(
|
|
34970
|
+
importName,
|
|
34971
|
+
Object.keys(schema).length ? schema : { properties: {} },
|
|
34972
|
+
name2,
|
|
34973
|
+
topLevel
|
|
34974
|
+
).pipe(
|
|
34941
34975
|
map2(
|
|
34942
34976
|
(source) => transformer.onTopLevel({
|
|
34943
34977
|
importName,
|
|
@@ -34959,7 +34993,7 @@ var make64 = gen2(function* () {
|
|
|
34959
34993
|
};
|
|
34960
34994
|
const flattenAllOf = (schema) => {
|
|
34961
34995
|
if ("allOf" in schema) {
|
|
34962
|
-
let out =
|
|
34996
|
+
let out = omit3(schema, "allOf");
|
|
34963
34997
|
for (const member of schema.allOf) {
|
|
34964
34998
|
let s = getSchema(member);
|
|
34965
34999
|
if ("allOf" in s) {
|
|
@@ -34974,6 +35008,16 @@ var make64 = gen2(function* () {
|
|
|
34974
35008
|
const transformer = yield* JsonSchemaTransformer;
|
|
34975
35009
|
const toSource = (importName, schema, currentIdentifier, topLevel = false) => {
|
|
34976
35010
|
schema = cleanupSchema(schema);
|
|
35011
|
+
if (typeof schema === "boolean") {
|
|
35012
|
+
if (schema === true) {
|
|
35013
|
+
return some2(transformer.onUnknown({ importName }));
|
|
35014
|
+
} else {
|
|
35015
|
+
return none2();
|
|
35016
|
+
}
|
|
35017
|
+
}
|
|
35018
|
+
if (typeof schema !== "object" || schema === null) {
|
|
35019
|
+
return none2();
|
|
35020
|
+
}
|
|
34977
35021
|
if ("properties" in schema) {
|
|
34978
35022
|
const obj = schema;
|
|
34979
35023
|
const required2 = obj.required ?? [];
|
|
@@ -35039,7 +35083,7 @@ var make64 = gen2(function* () {
|
|
|
35039
35083
|
if (!schema.$ref.startsWith("#")) {
|
|
35040
35084
|
return none2();
|
|
35041
35085
|
}
|
|
35042
|
-
const name2 = identifier2(schema.$ref
|
|
35086
|
+
const name2 = identifier2(refLastToken(schema.$ref));
|
|
35043
35087
|
return some2(transformer.onRef({ importName, name: name2 }));
|
|
35044
35088
|
} else if ("properties" in schema) {
|
|
35045
35089
|
return toSource(
|
|
@@ -35150,6 +35194,8 @@ var make64 = gen2(function* () {
|
|
|
35150
35194
|
return { $id: "/schemas/any" };
|
|
35151
35195
|
} else if (Array.isArray(schema)) {
|
|
35152
35196
|
return { anyOf: schema };
|
|
35197
|
+
} else if (typeof schema === "boolean") {
|
|
35198
|
+
return schema === false ? { not: {} } : { $id: "/schemas/any" };
|
|
35153
35199
|
}
|
|
35154
35200
|
return schema;
|
|
35155
35201
|
};
|
|
@@ -35174,7 +35220,7 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
|
|
|
35174
35220
|
if (options3.isNullable && options3.default === null) {
|
|
35175
35221
|
return `${S}.optionalWith(${S}.NullOr(${source}), { default: () => null })`;
|
|
35176
35222
|
}
|
|
35177
|
-
const defaultSource = options3.default !== void 0 && options3.default !== null ? `() => ${JSON.stringify(options3.default)} as const` : void 0;
|
|
35223
|
+
const defaultSource = options3.default !== void 0 && options3.default !== null ? `() => (${JSON.stringify(options3.default)} as const)` : void 0;
|
|
35178
35224
|
if (options3.isOptional) {
|
|
35179
35225
|
return defaultSource ? `${S}.optionalWith(${source}, { nullable: true, default: ${defaultSource} })` : `${S}.optionalWith(${source}, { nullable: true })`;
|
|
35180
35226
|
}
|
|
@@ -35275,6 +35321,9 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
|
|
|
35275
35321
|
},
|
|
35276
35322
|
onUnion({ importName, items }) {
|
|
35277
35323
|
return `${importName}.Union(${items.map((_) => `${toComment(_.description)}${_.source}`).join(",\n")})`;
|
|
35324
|
+
},
|
|
35325
|
+
onUnknown({ importName }) {
|
|
35326
|
+
return `${importName}.Unknown`;
|
|
35278
35327
|
}
|
|
35279
35328
|
});
|
|
35280
35329
|
});
|
|
@@ -35332,11 +35381,14 @@ export type ${name2} = (typeof ${name2})[keyof typeof ${name2}];` : `${toComment
|
|
|
35332
35381
|
return `{
|
|
35333
35382
|
${items.map(({ description, title, source }) => `${toComment(description)}${JSON.stringify(getOrNull(title))}: ${source}`).join(",\n ")}} as const
|
|
35334
35383
|
`;
|
|
35384
|
+
},
|
|
35385
|
+
onUnknown() {
|
|
35386
|
+
return "unknown";
|
|
35335
35387
|
}
|
|
35336
35388
|
})
|
|
35337
35389
|
);
|
|
35338
35390
|
function mergeSchemas(self, other) {
|
|
35339
|
-
if ("properties" in self
|
|
35391
|
+
if ("properties" in self || "properties" in other) {
|
|
35340
35392
|
return {
|
|
35341
35393
|
...other,
|
|
35342
35394
|
...self,
|
|
@@ -35344,7 +35396,10 @@ function mergeSchemas(self, other) {
|
|
|
35344
35396
|
...other.properties,
|
|
35345
35397
|
...self.properties
|
|
35346
35398
|
},
|
|
35347
|
-
required: [
|
|
35399
|
+
required: [
|
|
35400
|
+
...other.required || [],
|
|
35401
|
+
...self.required || []
|
|
35402
|
+
]
|
|
35348
35403
|
};
|
|
35349
35404
|
} else if ("anyOf" in self && "anyOf" in other) {
|
|
35350
35405
|
return {
|
|
@@ -35372,10 +35427,15 @@ function resolveAllOf(schema, context7, resolveRefs = true) {
|
|
|
35372
35427
|
if (schema.allOf.length === 0) {
|
|
35373
35428
|
return out2;
|
|
35374
35429
|
}
|
|
35375
|
-
|
|
35430
|
+
const resolvedMember = resolveAllOf(
|
|
35431
|
+
schema.allOf[0],
|
|
35432
|
+
context7,
|
|
35433
|
+
resolveRefs
|
|
35434
|
+
);
|
|
35435
|
+
out2 = mergeSchemas(out2, resolvedMember);
|
|
35376
35436
|
return resolveAllOf(out2, context7, resolveRefs);
|
|
35377
35437
|
}
|
|
35378
|
-
let out =
|
|
35438
|
+
let out = omit3(schema, "allOf");
|
|
35379
35439
|
for (const member of schema.allOf) {
|
|
35380
35440
|
out = mergeSchemas(out, resolveAllOf(member, context7, resolveRefs));
|
|
35381
35441
|
}
|
|
@@ -35387,7 +35447,7 @@ function resolveRef(schema, context7, recursive = false) {
|
|
|
35387
35447
|
if (!schema.$ref.startsWith("#")) {
|
|
35388
35448
|
return;
|
|
35389
35449
|
}
|
|
35390
|
-
const path2 = schema.$ref
|
|
35450
|
+
const path2 = decodeRefTokens(schema.$ref);
|
|
35391
35451
|
const name2 = identifier2(path2[path2.length - 1]);
|
|
35392
35452
|
let current = context7;
|
|
35393
35453
|
for (const key of path2) {
|
|
@@ -35468,7 +35528,7 @@ var make65 = gen2(function* () {
|
|
|
35468
35528
|
const context7 = { components };
|
|
35469
35529
|
const operations = [];
|
|
35470
35530
|
function resolveRef2(ref) {
|
|
35471
|
-
const parts2 = ref
|
|
35531
|
+
const parts2 = decodeRefTokens(ref);
|
|
35472
35532
|
let current = spec2;
|
|
35473
35533
|
for (const part of parts2) {
|
|
35474
35534
|
current = current[part];
|