MCPcopy Index your code
hub / github.com/glideapps/quicktype / parseRef

Function parseRef

src/JSONSchemaInput.ts:43–65  ·  view source on GitHub ↗
(ref: any)

Source from the content-addressed store, hash-verified

41}
42
43function parseRef(ref: any): [Ref, string] {
44 if (typeof ref !== "string") {
45 return panic("$ref must be a string");
46 }
47
48 let refName = "Something";
49
50 const parts = ref.split("/");
51 const elements: PathElement[] = [];
52 for (let i = 0; i < parts.length; i++) {
53 if (parts[i] === "#") {
54 elements.push({ kind: PathElementKind.Root });
55 refName = "Root";
56 } else if (parts[i] === "definitions" && i + 1 < parts.length) {
57 refName = parts[i + 1];
58 elements.push({ kind: PathElementKind.Definition, name: refName });
59 i += 1;
60 } else {
61 panic(`Could not parse JSON schema reference ${ref}`);
62 }
63 }
64 return [List(elements), refName];
65}
66
67function lookupDefinition(schema: StringMap, name: string): StringMap {
68 const definitions = checkStringMap(schema.definitions);

Callers 1

convertToTypeFunction · 0.85

Calls 1

panicFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…