Aller au contenu

Hotel builder

Le builder Hotel crée une entité Hotel, injecte son @type, valide les données de manière synchrone et rejette les propriétés inconnues.

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

Le schéma Zod LodgingBusinessSchema est également exporté pour la composition et la validation avancées.

import {
LodgingBusinessSchema,
type SchemaInput,
type SchemaOutput,
} from '@unschema-graph/core';
type HotelInput = SchemaInput<typeof LodgingBusinessSchema>;
type HotelOutput = SchemaOutput<typeof LodgingBusinessSchema, 'Hotel'>;
Propriété Type d’entrée Obligatoire Valeur par défaut / contraintes
@id string Non non-empty
name string Oui non-empty
address string | PostalAddress | EntityReference Oui —
image string | ImageObject Non non-empty
telephone string Non —
priceRange string Non —
url string Non —
geo GeoCoordinates Non —
openingHoursSpecification object | Array Non —
currenciesAccepted string Non —
paymentAccepted string Non —
sameAs string | Array Non —
servesCuisine string | Array Non —
menu string Non —
checkinTime string Non —
checkoutTime string Non —
numberOfRooms number Non integer; greater than 0; maximum: 9007199254740991
petsAllowed boolean | string Non —
amenityFeature string | Array | object | Array Non —
starRating object 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 Hotel.

import { Hotel } from '@unschema-graph/core';
const entity = Hotel({
"name": "Acme Paris",
"address": {
"streetAddress": "1 Rue de Rivoli",
"addressLocality": "Paris",
"postalCode": "75001",
"addressCountry": "FR"
}
});
{
"@type": "Hotel",
"name": "Acme Paris",
"address": {
"streetAddress": "1 Rue de Rivoli",
"addressLocality": "Paris",
"postalCode": "75001",
"addressCountry": "FR"
}
}
  • 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.

Utilisez Hotel.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.