@tim-smart/openapi-gen 0.4.12 → 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 -15
- 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,7 +34966,12 @@ var make64 = gen2(function* () {
|
|
|
34935
34966
|
isClass,
|
|
34936
34967
|
isEnum
|
|
34937
34968
|
});
|
|
34938
|
-
return toSource(
|
|
34969
|
+
return toSource(
|
|
34970
|
+
importName,
|
|
34971
|
+
Object.keys(schema).length ? schema : { properties: {} },
|
|
34972
|
+
name2,
|
|
34973
|
+
topLevel
|
|
34974
|
+
).pipe(
|
|
34939
34975
|
map2(
|
|
34940
34976
|
(source) => transformer.onTopLevel({
|
|
34941
34977
|
importName,
|
|
@@ -34957,7 +34993,7 @@ var make64 = gen2(function* () {
|
|
|
34957
34993
|
};
|
|
34958
34994
|
const flattenAllOf = (schema) => {
|
|
34959
34995
|
if ("allOf" in schema) {
|
|
34960
|
-
let out =
|
|
34996
|
+
let out = omit3(schema, "allOf");
|
|
34961
34997
|
for (const member of schema.allOf) {
|
|
34962
34998
|
let s = getSchema(member);
|
|
34963
34999
|
if ("allOf" in s) {
|
|
@@ -34972,6 +35008,16 @@ var make64 = gen2(function* () {
|
|
|
34972
35008
|
const transformer = yield* JsonSchemaTransformer;
|
|
34973
35009
|
const toSource = (importName, schema, currentIdentifier, topLevel = false) => {
|
|
34974
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
|
+
}
|
|
34975
35021
|
if ("properties" in schema) {
|
|
34976
35022
|
const obj = schema;
|
|
34977
35023
|
const required2 = obj.required ?? [];
|
|
@@ -35037,7 +35083,7 @@ var make64 = gen2(function* () {
|
|
|
35037
35083
|
if (!schema.$ref.startsWith("#")) {
|
|
35038
35084
|
return none2();
|
|
35039
35085
|
}
|
|
35040
|
-
const name2 = identifier2(schema.$ref
|
|
35086
|
+
const name2 = identifier2(refLastToken(schema.$ref));
|
|
35041
35087
|
return some2(transformer.onRef({ importName, name: name2 }));
|
|
35042
35088
|
} else if ("properties" in schema) {
|
|
35043
35089
|
return toSource(
|
|
@@ -35148,6 +35194,8 @@ var make64 = gen2(function* () {
|
|
|
35148
35194
|
return { $id: "/schemas/any" };
|
|
35149
35195
|
} else if (Array.isArray(schema)) {
|
|
35150
35196
|
return { anyOf: schema };
|
|
35197
|
+
} else if (typeof schema === "boolean") {
|
|
35198
|
+
return schema === false ? { not: {} } : { $id: "/schemas/any" };
|
|
35151
35199
|
}
|
|
35152
35200
|
return schema;
|
|
35153
35201
|
};
|
|
@@ -35172,7 +35220,7 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
|
|
|
35172
35220
|
if (options3.isNullable && options3.default === null) {
|
|
35173
35221
|
return `${S}.optionalWith(${S}.NullOr(${source}), { default: () => null })`;
|
|
35174
35222
|
}
|
|
35175
|
-
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;
|
|
35176
35224
|
if (options3.isOptional) {
|
|
35177
35225
|
return defaultSource ? `${S}.optionalWith(${source}, { nullable: true, default: ${defaultSource} })` : `${S}.optionalWith(${source}, { nullable: true })`;
|
|
35178
35226
|
}
|
|
@@ -35273,6 +35321,9 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
|
|
|
35273
35321
|
},
|
|
35274
35322
|
onUnion({ importName, items }) {
|
|
35275
35323
|
return `${importName}.Union(${items.map((_) => `${toComment(_.description)}${_.source}`).join(",\n")})`;
|
|
35324
|
+
},
|
|
35325
|
+
onUnknown({ importName }) {
|
|
35326
|
+
return `${importName}.Unknown`;
|
|
35276
35327
|
}
|
|
35277
35328
|
});
|
|
35278
35329
|
});
|
|
@@ -35330,11 +35381,14 @@ export type ${name2} = (typeof ${name2})[keyof typeof ${name2}];` : `${toComment
|
|
|
35330
35381
|
return `{
|
|
35331
35382
|
${items.map(({ description, title, source }) => `${toComment(description)}${JSON.stringify(getOrNull(title))}: ${source}`).join(",\n ")}} as const
|
|
35332
35383
|
`;
|
|
35384
|
+
},
|
|
35385
|
+
onUnknown() {
|
|
35386
|
+
return "unknown";
|
|
35333
35387
|
}
|
|
35334
35388
|
})
|
|
35335
35389
|
);
|
|
35336
35390
|
function mergeSchemas(self, other) {
|
|
35337
|
-
if ("properties" in self
|
|
35391
|
+
if ("properties" in self || "properties" in other) {
|
|
35338
35392
|
return {
|
|
35339
35393
|
...other,
|
|
35340
35394
|
...self,
|
|
@@ -35342,7 +35396,10 @@ function mergeSchemas(self, other) {
|
|
|
35342
35396
|
...other.properties,
|
|
35343
35397
|
...self.properties
|
|
35344
35398
|
},
|
|
35345
|
-
required: [
|
|
35399
|
+
required: [
|
|
35400
|
+
...other.required || [],
|
|
35401
|
+
...self.required || []
|
|
35402
|
+
]
|
|
35346
35403
|
};
|
|
35347
35404
|
} else if ("anyOf" in self && "anyOf" in other) {
|
|
35348
35405
|
return {
|
|
@@ -35370,10 +35427,15 @@ function resolveAllOf(schema, context7, resolveRefs = true) {
|
|
|
35370
35427
|
if (schema.allOf.length === 0) {
|
|
35371
35428
|
return out2;
|
|
35372
35429
|
}
|
|
35373
|
-
|
|
35430
|
+
const resolvedMember = resolveAllOf(
|
|
35431
|
+
schema.allOf[0],
|
|
35432
|
+
context7,
|
|
35433
|
+
resolveRefs
|
|
35434
|
+
);
|
|
35435
|
+
out2 = mergeSchemas(out2, resolvedMember);
|
|
35374
35436
|
return resolveAllOf(out2, context7, resolveRefs);
|
|
35375
35437
|
}
|
|
35376
|
-
let out =
|
|
35438
|
+
let out = omit3(schema, "allOf");
|
|
35377
35439
|
for (const member of schema.allOf) {
|
|
35378
35440
|
out = mergeSchemas(out, resolveAllOf(member, context7, resolveRefs));
|
|
35379
35441
|
}
|
|
@@ -35385,7 +35447,7 @@ function resolveRef(schema, context7, recursive = false) {
|
|
|
35385
35447
|
if (!schema.$ref.startsWith("#")) {
|
|
35386
35448
|
return;
|
|
35387
35449
|
}
|
|
35388
|
-
const path2 = schema.$ref
|
|
35450
|
+
const path2 = decodeRefTokens(schema.$ref);
|
|
35389
35451
|
const name2 = identifier2(path2[path2.length - 1]);
|
|
35390
35452
|
let current = context7;
|
|
35391
35453
|
for (const key of path2) {
|
|
@@ -35466,7 +35528,7 @@ var make65 = gen2(function* () {
|
|
|
35466
35528
|
const context7 = { components };
|
|
35467
35529
|
const operations = [];
|
|
35468
35530
|
function resolveRef2(ref) {
|
|
35469
|
-
const parts2 = ref
|
|
35531
|
+
const parts2 = decodeRefTokens(ref);
|
|
35470
35532
|
let current = spec2;
|
|
35471
35533
|
for (const part of parts2) {
|
|
35472
35534
|
current = current[part];
|