Skip to content

Answer builder

Creates a standalone Answer entity. The Answer builder injects @type, validates synchronously, and rejects unknown properties.

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

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

import {
AnswerSchema,
type SchemaInput,
type SchemaOutput,
} from '@unschema-graph/core';
type AnswerInput = SchemaInput<typeof AnswerSchema>;
type AnswerOutput = SchemaOutput<typeof AnswerSchema, 'Answer'>;
Property Input type Required Default / constraints
@id string No —
text string Yes non-empty

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

import { Answer } from '@unschema-graph/core';
const entity = Answer({
"text": "Use one validated graph per page."
});
{
"@type": "Answer",
"text": "Use one validated graph per page."
}
  • 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 Answer.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.