Recipe builder
Le builder Recipe crée une entité Recipe, injecte son @type,
valide les données de manière synchrone et rejette les propriétés inconnues.
// 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';Le schéma Zod RecipeSchema est également exporté pour la composition et la validation avancées.
Types TypeScript
Section intitulée « Types TypeScript »import { RecipeSchema, type SchemaInput, type SchemaOutput,} from '@unschema-graph/core';
type RecipeInput = SchemaInput<typeof RecipeSchema>;type RecipeOutput = SchemaOutput<typeof RecipeSchema, 'Recipe'>;Propriétés d’entrée
Section intitulée « Propriétés d’entrée »| Propriété | Type d’entrée | Obligatoire | Valeur par défaut / contraintes |
|---|---|---|---|
@id |
string | Non | non-empty |
name |
string | Oui | non-empty |
image |
string | ImageObject | Array<string | ImageObject> | Oui | non-empty |
recipeIngredient |
Array |
Oui | minimum items: 1 |
recipeInstructions |
Array<string | object> | string | Oui | — |
author |
string | Person | Organization | EntityReference | Non | non-empty |
datePublished |
string | number | Date | Non | non-empty |
description |
string | Non | — |
prepTime |
string | number | DurationObject | Non | non-empty; greater than 0 |
cookTime |
string | number | DurationObject | Non | non-empty; greater than 0 |
totalTime |
string | number | DurationObject | Non | non-empty; greater than 0 |
recipeYield |
string | number | Non | — |
recipeCategory |
string | Array |
Non | — |
recipeCuisine |
string | Array |
Non | — |
keywords |
string | Array |
Non | — |
nutrition |
object | Non | — |
aggregateRating |
AggregateRating | Non | — |
Les alias ci-dessus restent la référence exacte, notamment pour les objets imbriqués. Le builder
accepte aussi une configuration de validation en second argument et possède une sortie dont le
@type vaut toujours Recipe.
Exemple minimal
Section intitulée « Exemple minimal »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." } ]}Relations et recettes
Section intitulée « Relations et recettes »- Builders liés :
Article,BlogPosting,NewsArticle,HowTo - Utilisé par : aucune recette dédiée
- Sources externes : Schema.org Recipe · Google Search Central
Erreurs fréquentes
Section intitulée « Erreurs fréquentes »- Passer une propriété inconnue au builder strict.
- Utiliser une donnée source privée d’une propriété obligatoire.
- Supposer qu’un Schema.org valide garantit un affichage dans la recherche.
Validation
Section intitulée « Validation »Utilisez Recipe.safeParse(input) pour les données externes. Pour une extension
Schema.org non encore modélisée, validez d’abord l’entité puis utilisez
withAdditionalProperties(). N’ajoutez jamais une propriété inventée au builder.