openapi-typescript
Advanced tools
Comparing version 6.2.5 to 6.2.6
@@ -76,12 +76,25 @@ import c from "ansi-colors"; | ||
return { filename: ".", path: [] }; | ||
if (!ref.includes("#")) | ||
return { filename: ref, path: [] }; | ||
const [filename, path] = ref.split("#"); | ||
return { | ||
filename: filename || ".", | ||
path: path | ||
.split("/") | ||
.filter((p) => !!p && p !== "properties") | ||
.map(decodeRef), | ||
}; | ||
if (ref.includes("#/")) { | ||
const [filename, pathStr] = ref.split("#"); | ||
const parts = pathStr.split("/"); | ||
const path = []; | ||
for (const part of parts) { | ||
if (!part || part === "properties") | ||
continue; | ||
path.push(decodeRef(part)); | ||
} | ||
return { filename: filename || ".", path }; | ||
} | ||
else if (ref.includes('["')) { | ||
const parts = ref.split('["'); | ||
const path = []; | ||
for (const part of parts) { | ||
const sanitized = part.replace('"]', "").trim(); | ||
if (!sanitized || sanitized === "properties") | ||
continue; | ||
path.push(sanitized); | ||
} | ||
return { filename: ".", path }; | ||
} | ||
return { filename: ref, path: [] }; | ||
} | ||
@@ -88,0 +101,0 @@ export function parseTSIndex(type) { |
{ | ||
"name": "openapi-typescript", | ||
"description": "Generate TypeScript types from Swagger OpenAPI specs", | ||
"version": "6.2.5", | ||
"version": "6.2.6", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Drew Powers", |
@@ -109,11 +109,27 @@ import c from "ansi-colors"; | ||
if (typeof ref !== "string") return { filename: ".", path: [] }; | ||
if (!ref.includes("#")) return { filename: ref, path: [] }; | ||
const [filename, path] = ref.split("#"); | ||
return { | ||
filename: filename || ".", | ||
path: path | ||
.split("/") // split by special character | ||
.filter((p) => !!p && p !== "properties") // remove empty parts and "properties" (gets flattened by TS) | ||
.map(decodeRef), // decode encoded chars | ||
}; | ||
// OpenAPI $ref | ||
if (ref.includes("#/")) { | ||
const [filename, pathStr] = ref.split("#"); | ||
const parts = pathStr.split("/"); | ||
const path: string[] = []; | ||
for (const part of parts) { | ||
if (!part || part === "properties") continue; // remove empty parts and "properties" (gets flattened by TS) | ||
path.push(decodeRef(part)); | ||
} | ||
return { filename: filename || ".", path }; | ||
} | ||
// js-yaml $ref | ||
else if (ref.includes('["')) { | ||
const parts = ref.split('["'); | ||
const path: string[] = []; | ||
for (const part of parts) { | ||
const sanitized = part.replace('"]', "").trim(); | ||
if (!sanitized || sanitized === "properties") continue; | ||
path.push(sanitized); | ||
} | ||
return { filename: ".", path }; | ||
} | ||
// remote $ref | ||
return { filename: ref, path: [] }; | ||
} | ||
@@ -120,0 +136,0 @@ |
Sorry, the diff of this file is not supported yet
295437
4748