From b8561f727618f4a0b1fdc664f57140ccff85e998 Mon Sep 17 00:00:00 2001 From: ericszentivanyi <247076009+ericszentivanyi@users.noreply.github.com> Date: Tue, 13 Jan 2026 23:39:10 -0500 Subject: [PATCH] fix!: require `title` when `definitions` are empty --- typify-impl/src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/typify-impl/src/lib.rs b/typify-impl/src/lib.rs index 2f791ba2..d3e4ae51 100644 --- a/typify-impl/src/lib.rs +++ b/typify-impl/src/lib.rs @@ -51,6 +51,8 @@ pub enum Error { type_name: Option, reason: String, }, + #[error("invalid root schema: {reason}")] + InvalidRootSchema { reason: String }, } impl Error { @@ -790,17 +792,21 @@ impl TypeSpace { definitions, } = schema; + let title = schema.metadata.as_ref().and_then(|m| m.title.as_ref()); + + if definitions.is_empty() && title.is_none() { + return Err(Error::InvalidRootSchema { + reason: "title is required when there are no definitions".to_string(), + }); + } + let mut defs = definitions .into_iter() .map(|(key, schema)| (RefKey::Def(key), schema)) .collect::>(); // Does the root type have a name (otherwise... ignore it) - let root_type = schema - .metadata - .as_ref() - .and_then(|m| m.title.as_ref()) - .is_some(); + let root_type = title.is_some(); if root_type { defs.push((RefKey::Root, schema.into()));