GitbookIO/gitbook · error · Error

Unsupported schema type: ${schema.type}

Error message

Unsupported schema type: ${schema.type}

What it means

Thrown by inferDefaultInputValueFromJSONSchema in @gitbook/expr when the schema type falls into the switch's default branch. Only string, number, integer, boolean, null, array, and object are handled; any other (or missing/invalid) type value such as undefined is rejected.

Source

Thrown at packages/expr/src/input-values.ts:58

        case 'array': {
            if (schema.items && Array.isArray(schema.items)) {
                return schema.items.map((itemSchema) => {
                    if (typeof itemSchema === 'boolean') {
                        return false;
                    }
                    return inferDefaultInputValueFromJSONSchema(itemSchema);
                });
            }
            return [];
        }
        case 'string':
        case 'number':
        case 'integer':
        case 'boolean':
        case 'null':
            return inferDefaultInputValueFromPrimitive(schema);
        default:
            throw new Error(`Unsupported schema type: ${schema.type}`);
    }
}

function inferDefaultInputValueFromPrimitive(schema: JSONSchema7): InputValuesType {
    switch (schema.type) {
        case 'boolean':
            return true;
        case 'number':
        case 'integer':
            return 1234;
        case 'string': {
            const enumValues = schema.enum?.filter(filterOutNullable);
            return enumValues?.[0] ?? 'default';
        }
        case 'null':
            return null;
        default:
            throw new Error(`Unsupported schema type: ${schema.type}`);

View on GitHub (pinned to db67585ee2)

Solutions

  1. Ensure every schema passed has a concrete, supported type (string|number|integer|boolean|null|array|object)
  2. Normalize combinator schemas by resolving oneOf/anyOf to one concrete branch before inference
  3. Add a default branch returning a sensible fallback instead of relying on the library throwing

Example fix

// before
const value = inferDefaultInputValueFromJSONSchema({ oneOf: [] }); // no type

// after
const value = inferDefaultInputValueFromJSONSchema({ type: 'string' });
Defensive patterns

Strategy: type-guard

Validate before calling

const SUPPORTED = new Set(['string','number','integer','boolean','null','array','object']);
if (!SUPPORTED.has(schema.type ?? '')) {
    // normalize schema (resolve oneOf/anyOf) before inference
}

Type guard

function hasSupportedSchemaType(schema: JSONSchema7): boolean {
    return ['string','number','integer','boolean','null','array','object'].includes(schema.type as string);
}

Prevention

When it happens

Trigger: Passing a schema whose type is undefined (e.g. a schema using oneOf/anyOf without a top-level type), a typo'd type, or a type added by newer JSON Schema drafts that this version doesn't know.

Common situations: Schemas with combinators (oneOf/anyOf/allOf) at the root instead of a concrete type; hand-built schema objects missing the type field; version mismatches between the JSON Schema producer and @gitbook/expr's supported types.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of GitbookIO/gitbook@db67585ee2 (2026-08-28). Data as JSON: /api/errors/adbf9d1201d61a86. Report an issue: GitHub.