Skip to content

NewsArticle builder

Creates a NewsArticle using the strict Article input schema. The NewsArticle builder injects @type, validates synchronously, and rejects unknown properties.

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

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

import {
ArticleSchema,
type SchemaInput,
type SchemaOutput,
} from '@unschema-graph/core';
type NewsArticleInput = SchemaInput<typeof ArticleSchema>;
type NewsArticleOutput = SchemaOutput<typeof ArticleSchema, 'NewsArticle'>;
Property Input type Required Default / constraints
@id string No non-empty
headline string Yes non-empty
image string | ImageObject | Array<string | ImageObject> Yes non-empty
datePublished string | number | Date Yes non-empty
dateModified string | number | Date No non-empty
author string | Person | Organization | EntityReference | Array<string | Person | Organization | EntityReference> Yes non-empty
publisher string | Organization | EntityReference No non-empty
description string No —
articleBody string No —
articleSection string | Array No —
keywords string | Array No —
inLanguage string No —
mainEntityOfPage string | object No —
wordCount number No integer; greater than 0; maximum: 9007199254740991
speakable string | Array | object 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: 'NewsArticle'.

import { NewsArticle } from '@unschema-graph/core';
const entity = NewsArticle({
"headline": "Structured data with Astro",
"image": "/images/structured-data.jpg",
"datePublished": "2026-09-29",
"author": "Ada Lovelace"
});
{
"@type": "NewsArticle",
"headline": "Structured data with Astro",
"image": "/images/structured-data.jpg",
"datePublished": "2026-09-29",
"author": {
"@type": "Person",
"name": "Ada Lovelace"
}
}
  • 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 NewsArticle.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.