Skip to content

Rating builder

Creates a Rating with default best and worst values. The Rating builder injects @type, validates synchronously, and rejects unknown properties.

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

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

import {
RatingSchema,
type SchemaInput,
type SchemaOutput,
} from '@unschema-graph/core';
type RatingInput = SchemaInput<typeof RatingSchema>;
type RatingOutput = SchemaOutput<typeof RatingSchema, 'Rating'>;
Property Input type Required Default / constraints
@id string No —
ratingValue number | string Yes —
bestRating number | string No default: 5
worstRating number | string No default: 1

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: 'Rating'.

import { Rating } from '@unschema-graph/core';
const entity = Rating({
"ratingValue": 4.5
});
{
"@type": "Rating",
"ratingValue": 4.5,
"bestRating": 5,
"worstRating": 1
}
  • 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 Rating.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.