Skip to content

Recipe builder

Creates a Recipe and normalizes instruction and duration shorthands. The Recipe builder injects @type, validates synchronously, and rejects unknown properties.

// Astro — shown first when Astro is selected
import { Recipe } from '@unschema-graph/astro';
// Svelte 5
import { Recipe } from '@unschema-graph/svelte';
// Core / Node.js
import { Recipe } from '@unschema-graph/core';
import { RecipeSchema } from '@unschema-graph/core';

The RecipeSchema Zod schema is also exported for composition and advanced validation.

import {
RecipeSchema,
type SchemaInput,
type SchemaOutput,
} from '@unschema-graph/core';
type RecipeInput = SchemaInput<typeof RecipeSchema>;
type RecipeOutput = SchemaOutput<typeof RecipeSchema, 'Recipe'>;
Property Input type Required Default / constraints
@id string No non-empty
name string Yes non-empty
image string | ImageObject | Array<string | ImageObject> Yes non-empty
recipeIngredient Array Yes minimum items: 1
recipeInstructions Array<string | object> | string Yes —
author string | Person | Organization | EntityReference No non-empty
datePublished string | number | Date No non-empty
description string No —
prepTime string | number | DurationObject No non-empty; greater than 0
cookTime string | number | DurationObject No non-empty; greater than 0
totalTime string | number | DurationObject No non-empty; greater than 0
recipeYield string | number No —
recipeCategory string | Array No —
recipeCuisine string | Array No —
keywords string | Array No —
nutrition object No —
aggregateRating AggregateRating No —

The aliases above remain the exact authority for nested object types. The builder also accepts a validation configuration as its second argument and always returns @type: 'Recipe'.

import { Recipe } from '@unschema-graph/core';
const entity = Recipe({
"name": "Tomato pasta",
"image": "/images/pasta.jpg",
"recipeIngredient": [
"200 g pasta",
"2 tomatoes"
],
"recipeInstructions": [
"Cook the pasta.",
"Add the tomatoes."
]
});
{
"@type": "Recipe",
"name": "Tomato pasta",
"image": "/images/pasta.jpg",
"recipeIngredient": [
"200 g pasta",
"2 tomatoes"
],
"recipeInstructions": [
{
"@type": "HowToStep",
"text": "Cook the pasta."
},
{
"@type": "HowToStep",
"text": "Add the tomatoes."
}
]
}
  • Passing an unknown property to the strict builder.
  • Using source data that is missing a required property.
  • Assuming valid Schema.org guarantees a search appearance.

Use Recipe.safeParse(input) for external data. If Schema.org supports a property that is not modeled yet, validate the entity first and then use withAdditionalProperties(). Never pass invented properties to the strict builder.