Skip to main content

schema_org 2.1.1 copy "schema_org: ^2.1.1" to clipboard
schema_org: ^2.1.1 copied to clipboard

Type-safe Dart classes for the full Schema.org vocabulary. Serialize to JSON-LD on any platform, or inject it into the page on Flutter web.

2.1.1 #

  • Shorten the package description to the 60–180 characters pub.dev recommends.

2.1.0 #

Fixes #

  • Enum members serialize to their own URL. Every member of a generated enum previously serialized to the enumeration's URL (e.g. SchemaItemAvailability.inStock → https://schema.org/ItemAvailability), which search engines reject. Members now emit their canonical URL (https://schema.org/InStock).
  • Subtypes are accepted. Values were validated with an exact runtimeType match, so a SchemaCorporation as founder or a SchemaPatient as alumni threw UnsupportedTypeException even though they compile and are valid Schema.org. Union-typed fields are now checked with is; single-typed fields rely on the Dart type system.
  • Web writer works when compiled to WebAssembly. The platform switch used dart.library.html, which is false under Wasm, so writeJsonLd silently did nothing there. It now uses dart.library.js_interop, as the Dart package:web migration guide recommends.
  • Doc comments are no longer truncated. The parser cut descriptions at the last :, mangling 454 doc comments (e.g. Organization.department).
  • Deprecated enum members link to their own Schema.org page.

Changes #

  • @context only on the root node. Nested objects no longer repeat "@context": "https://schema.org", matching Schema.org and Google examples. Nested objects with nothing but @type are dropped.
  • Vocabulary updated to Schema.org v30.1. Adds DeclarationOfConformity, DeliveryTimeSettings, DigitalProductPassport, EnvironmentalProductDeclaration, ProductReturnEnumeration, ProductReturnPolicy and new properties such as authorizedRepresentative.
  • Leaner generated code. Serialization no longer re-walks nested maps at every inheritance level, generated files no longer import themselves, and SchemaOrg is a single class backed by a small platform-specific script writer.

2.0.0 #

Breaking release. The web writer has been rebuilt on top of modern Flutter web interop (package:web + dart:js_interop), the generated class hierarchy now uses real Dart inheritance, and the Schema.org type mapping has been corrected. Callers of the original 1.x API need to adapt — see the "Migrating" notes below.

New #

  • SchemaOrg.toJsonLdString(schema) — a platform-agnostic helper that returns the pretty-printed JSON-LD string for any schema value. Works on web, mobile, and desktop; use it when you need the payload rather than DOM side-effects (SSR, logging, snapshot tests).
  • package:web-backed writer. SchemaOrg.writeJsonLd now uses package:web and writes via the script element's .text property so property values containing < or & no longer need to be HTML-escaped before serialization.
  • Real inheritance in generated classes. SchemaPerson extends SchemaThing, SchemaOrganization extends SchemaThing, and 824 of 829 generated classes gain a proper extends chain. is SchemaThing checks finally return true for subclasses. Multi-parent classes extends the first concrete parent and implements the rest.
  • @Deprecated annotations on superseded fields, classes, and enum values. 82 generated files now carry annotations sourced from Schema.org's schema:supersededBy metadata and the analyzer surfaces warnings when a deprecated member is used.
  • Public re-exports from package:schema_org/schema_org.dart: SchemaSerializable and UnsupportedTypeException are now part of the top-level library surface.

Breaking changes #

  • Minimum Flutter/Dart. Requires Flutter >=3.27.0 and Dart ^3.6.0. Older versions are no longer supported.
  • dart:html is gone. If you depended on any dart:html types leaking through from this package's exports, switch to package:web.
  • Type mapping: Number → num (was int). Fields whose Schema.org range is Number or Float are now num?, preserving fractional values. int x = schema.someNumberField needs to become num x = schema.someNumberField (or a cast).
  • Abstract enumeration classes now implements SchemaSerializable. Third-party types implementing an abstract enumeration interface (e.g. SchemaStatusEnumeration) must provide a toJsonLd() method.
  • Generated classes use extends. Generated fields on a subclass are now inherited from the extends chain rather than redeclared, so reflection over "own" fields returns fewer entries. Field access via the public API is unchanged.
  • Enum parents that are themselves concrete enums fall back to implements SchemaSerializable rather than implements SchemaParentEnum. Dart enums cannot implement other enums, so the parent relationship is semantic only (e.g. WearableSizeSystemEnumeration vs. SizeSystemEnumeration).
  • Generated classes classified differently. Nodes whose parents all descend from Enumeration (e.g. MedicalSpecialty) are now emitted as enums; previously a handful leaked through as classes. If you were constructing one of these directly, switch to the enum value.

Fixes #

  • Nested schema serialization no longer throws. convertToJsonLd now calls toJsonLd() on SchemaSerializable values, fixing a runtime crash when a schema object was passed as another schema's property (e.g. SchemaOrganization(founder: SchemaPerson(...))).
  • Duplicate supported-type hints removed. Ranges that collapse to the same Dart type (Text | URL → String) no longer produce Supported types: [String], [String] comments or redundant runtime type checks.
  • Foreign-namespace parents are dropped. rdfs:subClassOf targets from namespaces other than schema: (e.g. fibo-fnd-agr-ctr:, cmns-dt:) are filtered out so WarrantyPromise and friends no longer try to extend non-existent Dart classes.
  • Multi-typed JSON-LD nodes are picked up. Nodes declared as both DataType and rdfs:Class (e.g. Quantity) no longer fall off the generation pipeline.
  • removeEmpty handles lists. Lists with all-null entries collapse out of the output; lists with real entries are preserved.
  • Parser tolerates missing descriptions. The parser no longer crashes when a Schema.org node ships without an rdfs:comment / rdfs:label — a common situation with newer pending terms.

Parser + tooling #

  • schema_parser CLI accepts --out to redirect generated files into a scratch directory for review.
  • Generator emits a stable copyright + "GENERATED CODE" header on every file, including a file-level ignore_for_file: deprecated_member_use_from_same_package so internal super-forwarding of deprecated parent fields doesn't drown the analyzer output.
  • Dropped unused build_runner dependency and the orphan build.yaml.

Docs + hygiene #

  • Added NOTICE attributing Oddbit and the Schema.org vocabulary, with redistribution terms matching flutter_facebook_app_events.
  • Apache-2.0 copyright header on every hand-written and generated source file.
  • Rewritten README.md with usage, the architecture diagram, the type mapping table, and known compromises.
  • Expanded tests: 11 tests in the main package (nested serialization regression, list handling, toJsonLdString envelope, and more) and 22 tests in the parser (code-generator shape tests for extends, multi-parent, deprecation; classifier edge cases).

Migrating from 1.x #

Most call-sites stay identical:

SchemaOrg.writeJsonLd(SchemaOrganization(name: 'Oddbit'));

New paths that were not available in 1.x:

// Works on every target, not just web.
final ldJson = SchemaOrg.toJsonLdString(SchemaOrganization(name: 'Oddbit'));

If your code grabbed an int from a Schema.org Number field:

// Before (1.x)
int duration = movie.duration;
// After (2.x)
final num duration = movie.duration;
// or, if you know the value is an int
final int duration = movie.duration.toInt();

If you implemented a Schema.org abstract enumeration interface yourself (rare), add a toJsonLd() method returning the string you want the value to serialize to.

1.0.3 #

  • Pretty printing JSON objects
  • Correcting class references in documentation

1.0.2 #

  • Fixing dart package analysis feedback

1.0.1 #

  • Fixing image in README
  • Renaming 3d_model.dart -> three_d_model.dart
  • Fixing flutter analyze feedback

1.0.0 #

  • Initial release.
9
likes
160
points
107
downloads

Documentation

API reference

Publisher

verified publisheroddbit.id

Weekly Downloads

Type-safe Dart classes for the full Schema.org vocabulary. Serialize to JSON-LD on any platform, or inject it into the page on Flutter web.

Homepage
Repository (GitHub)
View/report issues

License

Apache-2.0 (license)

Dependencies

flutter, web

More

Packages that depend on schema_org