function _scan()

in packages/tasks-gen/scripts/inference-tei-import.ts [54:93]


	function _scan(data: JsonValue) {
		if (Array.isArray(data) || data instanceof Array) {
			for (const item of data) {
				_scan(item);
			}
		} else if (data && typeof data === "object") {
			for (const key of Object.keys(data)) {
				if (key === "$ref" && data[key] === "#/components/schemas/Input") {
					// Special case: keep input as string or string[]
					// but not Union[List[Union[List[int], int, str]], str]
					// data.delete(key);
					delete data[key];
					data["title"] = "FeatureExtractionInputs";
					data["description"] = "The text or list of texts to embed.";
					data["oneOf"] = [{ type: "string" }, { type: "array", items: { type: "string" } }];
				} else if (key === "$ref" && typeof data[key] === "string") {
					// Verify reference exists
					const ref = (data[key] as string).split("/").pop() ?? "";
					if (!components[ref]) {
						throw new Error(`Reference not found in components: ${data[key]}`);
					}

					// Add reference to components to export (and scan it too)
					let newRef = camelFullName + ref.replace(camelName, "");
					// remove duplicated InputInput or OutputOutput in naming
					newRef = newRef.replace("InputInput", "Input").replace("OutputOutput", "Output");
					if (!filteredComponents[newRef]) {
						components[ref]["title"] = newRef; // Rename title to avoid conflicts
						filteredComponents[newRef] = components[ref];
						_scan(components[ref]);
					}

					// Updating the reference to new format
					data[key] = `#/$defs/${newRef}`;
				} else {
					_scan(data[key]);
				}
			}
		}
	}