can1357/oh-my-pi · error · OmpTypeError

unsupported JSON Schema type: ${kind}

Error message

unsupported JSON Schema type: ${kind}

What it means

`fromJsonSchema` supports the core JSON Schema types (`string`, `number`, `integer`, `boolean`, `object`, `array`) but the schema declared a `type` value outside that set (e.g. `"null"` alone, or a misspelled type). The lowering pass throws `OmpTypeError` naming the unsupported kind.

Source

Thrown at packages/omptype/src/from-json-schema.ts:145

				if (typeof node.minimum === "number") ir.min = node.minimum;
				if (typeof node.maximum === "number") ir.max = node.maximum;
				if (typeof node.exclusiveMinimum === "number") {
					ir.min = node.exclusiveMinimum;
					ir.xmin = true;
				}
				if (typeof node.exclusiveMaximum === "number") {
					ir.max = node.exclusiveMaximum;
					ir.xmax = true;
				}
				if (typeof node.multipleOf === "number") ir.divisor = node.multipleOf;
				return ir;
			}
			case "object":
				return this.#lowerObject(node);
			case "array":
				return this.#lowerArray(node);
			default:
				throw new OmpTypeError(`unsupported JSON Schema type: ${kind}`);
		}
	}

	#lowerString(node: JsonSchema): IR {
		const base: IR = { k: "string" };
		if (typeof node.minLength === "number") base.min = node.minLength;
		if (typeof node.maxLength === "number") base.max = node.maxLength;
		if (node.format === "uri" || node.format === "url") base.url = true;

		const members: IR[] = [];
		if (typeof node.format === "string") {
			const keyword = FORMAT_KEYWORDS[node.format];
			if (keyword !== undefined) {
				const formatIR = keywordIR(keyword);
				if (formatIR !== undefined) members.push(formatIR);
			}
		}
		if (typeof node.pattern === "string") members.push(patternIR(new RegExp(node.pattern)));

View on GitHub (pinned to 9690622007)

Solutions

  1. Use union syntax `{ "type": ["string", "null"] }` instead of `"null"` as a sole/extra type if unions are supported; otherwise drop `"null"`.
  2. Fix typos and stray whitespace in the `type` field; use only string|number|integer|boolean|object|array.
  3. Replace dialect-specific types (`float` → `number`, `integer64` → `integer`) before conversion.

Example fix

// before
{ "type": "float" }
// after
{ "type": "number" }
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED = new Set(["string", "number", "integer", "boolean", "object", "array"]);
function hasSupportedTypes(node: Record<string, unknown>): boolean {
  const t = node.type;
  const types = Array.isArray(t) ? t : t !== undefined ? [t] : [];
  return types.every(x => SUPPORTED.has(String(x).trim()));
}

Try / catch

try {
  const t = fromJsonSchema(schema);
} catch (err) {
  if (err instanceof Error && err.message.startsWith("unsupported JSON Schema type")) {
    throw new Error(`Normalize the type field: ${err.message}`);
  }
  throw err;
}

Prevention

When it happens

Trigger: `{"type": "null"}` (sole type), `{"type": "integer "}` with stray whitespace, `{"type": "float"}`, or custom pseudo-types from dialects the converter doesn't know.

Common situations: OpenAPI 3.x schemas using `nullable: true` with `type: "null"`; vendor dialects (`integer64`); typo'd type names in hand-written schemas.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/a3b40d961ef6f309. Report an issue: GitHub.