Recipe builder
Creates a Recipe and normalizes instruction and duration shorthands. The Recipe builder injects @type, validates synchronously, and
rejects unknown properties.
Import
Section titled “Import”// Astro — shown first when Astro is selectedimport { Recipe } from '@unschema-graph/astro';
// Svelte 5import { Recipe } from '@unschema-graph/svelte';
// Core / Node.jsimport { Recipe } from '@unschema-graph/core';import { RecipeSchema } from '@unschema-graph/core';The RecipeSchema Zod schema is also exported for composition and advanced validation.
TypeScript types
Section titled “TypeScript types”import { RecipeSchema, type SchemaInput, type SchemaOutput,} from '@unschema-graph/core';
type RecipeInput = SchemaInput<typeof RecipeSchema>;type RecipeOutput = SchemaOutput<typeof RecipeSchema, 'Recipe'>;Input properties
Section titled “Input properties”| 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'.
Minimal example
Section titled “Minimal example”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." ]});Output
Section titled “Output”{ "@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." } ]}Relationships and recipes
Section titled “Relationships and recipes”- Related builders:
Article,BlogPosting,NewsArticle,HowTo - Used by: no dedicated recipe
- External sources: Schema.org Recipe · Google Search Central
Common errors
Section titled “Common errors”- 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.
Validation
Section titled “Validation”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.