GitbookIO/gitbook · error · Error
Expected schema of object to be provided: ${schema.type}
Error message
Expected schema of object to be provided: ${schema.type} What it means
Thrown by inferDefaultInputValuesFromObjectJSONSchema in @gitbook/expr when the passed JSON schema is not of type 'object' or has no properties map. The function only produces a Record<string, InputValuesType> from an object schema's properties, so arrays, strings, or object schemas without properties are rejected.
Source
Thrown at packages/expr/src/input-values.ts:20
import { filterOutNullable } from './utils';
type InputValuesType =
| null
| string
| number
| boolean
| { [key: string]: InputValuesType }
| InputValuesType[];
/**
* Infers a default inputValues object based on the JSON schema of an object.
*/
export function inferDefaultInputValuesFromObjectJSONSchema(
schema: JSONSchema7
): Record<string, InputValuesType> {
if (schema.type !== 'object' || !schema.properties) {
throw new Error(`Expected schema of object to be provided: ${schema.type}`);
}
const result: Record<string, InputValuesType> = {};
for (const [key, propertySchema] of Object.entries(schema.properties)) {
if (typeof propertySchema === 'boolean') {
continue;
}
result[key] = inferDefaultInputValueFromJSONSchema(propertySchema);
}
return result;
}
function inferDefaultInputValueFromJSONSchema(schema: JSONSchema7): InputValuesType {
switch (schema.type) {
case 'object':View on GitHub (pinned to db67585ee2)
Solutions
- Check schema.type === 'object' and schema.properties exists before calling; use inferDefaultInputValueFromJSONSchema for non-object schemas
- Dereference $refs first so the concrete type/properties are present
- If the input really is an array/scalar, switch to the single-value inference API
Example fix
// before
const values = inferDefaultInputValuesFromObjectJSONSchema(arraySchema); // type: 'array'
// after
const values =
schema.type === 'object'
? inferDefaultInputValuesFromObjectJSONSchema(schema)
: { value: inferDefaultInputValueFromJSONSchema(schema) }; Defensive patterns
Strategy: type-guard
Validate before calling
const isObjectSchema = (s: JSONSchema7) => s.type === 'object' && !!s.properties;
Type guard
function isObjectJSONSchema(schema: JSONSchema7): schema is JSONSchema7 & { type: 'object'; properties: Record<string, JSONSchema7Definition> } {
return schema.type === 'object' && typeof schema.properties === 'object' && schema.properties !== null;
} Prevention
- Dereference $refs before inferring defaults
- Route non-object schemas to inferDefaultInputValueFromJSONSchema
- Validate generated schemas with a JSON Schema meta-validator first
When it happens
Trigger: Calling defaultInputValues or inferDefaultInputValuesFromObjectJSONSchema with a schema whose type is 'array', 'string', 'number', or an object schema missing/empty properties (undefined properties triggers it too).
Common situations: Feeding a JSON Schema that describes an array or scalar instead of an object; schemas generated from tooling that omit properties; passing a $ref that hasn't been dereferenced so type/properties are absent; version changes in @gitbook/expr tightening schema requirements.
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
- Unsupported schema type: ${schema.type}
- Invalid hex color provided: ${originalHex}
- Invalid nodes found when parsing
- Empty or invalid expression
- invalid
AI-assisted analysis of GitbookIO/gitbook@db67585ee2 (2026-08-28).
Data as JSON: /api/errors/61b037b4d4ee9111.
Report an issue: GitHub.