schema_org 2.0.0
schema_org: ^2.0.0 copied to clipboard
JSON-LD Flutter/Dart classes for the full Schema.org vocabulary, generated from the official schema distribution. Emit structured data from Flutter web apps with type-safe constructors, or serialize t [...]
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.writeJsonLdnow usespackage:weband writes via the script element's.textproperty 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 properextendschain.is SchemaThingchecks finally returntruefor subclasses. Multi-parent classesextendsthe first concrete parent andimplementsthe rest. @Deprecatedannotations on superseded fields, classes, and enum values. 82 generated files now carry annotations sourced from Schema.org'sschema:supersededBymetadata and the analyzer surfaces warnings when a deprecated member is used.- Public re-exports from
package:schema_org/schema_org.dart:SchemaSerializableandUnsupportedTypeExceptionare now part of the top-level library surface.
Breaking changes #
- Minimum Flutter/Dart. Requires Flutter
>=3.27.0and Dart^3.6.0. Older versions are no longer supported. dart:htmlis gone. If you depended on anydart:htmltypes leaking through from this package's exports, switch topackage:web.- Type mapping:
Number→num(wasint). Fields whose Schema.org range isNumberorFloatare nownum?, preserving fractional values.int x = schema.someNumberFieldneeds to becomenum 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 atoJsonLd()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 SchemaSerializablerather thanimplements SchemaParentEnum. Dart enums cannot implement other enums, so the parent relationship is semantic only (e.g.WearableSizeSystemEnumerationvs.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.
convertToJsonLdnow callstoJsonLd()onSchemaSerializablevalues, 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 produceSupported types: [String], [String]comments or redundant runtime type checks. - Foreign-namespace parents are dropped.
rdfs:subClassOftargets from namespaces other thanschema:(e.g.fibo-fnd-agr-ctr:,cmns-dt:) are filtered out soWarrantyPromiseand friends no longer try to extend non-existent Dart classes. - Multi-typed JSON-LD nodes are picked up. Nodes declared as both
DataTypeandrdfs:Class(e.g.Quantity) no longer fall off the generation pipeline. removeEmptyhandles 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_parserCLI accepts--outto 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_packageso internal super-forwarding of deprecated parent fields doesn't drown the analyzer output. - Dropped unused
build_runnerdependency and the orphanbuild.yaml.
Docs + hygiene #
- Added
NOTICEattributing Oddbit and the Schema.org vocabulary, with redistribution terms matchingflutter_facebook_app_events. - Apache-2.0 copyright header on every hand-written and generated source file.
- Rewritten
README.mdwith usage, the architecture diagram, the type mapping table, and known compromises. - Expanded tests: 11 tests in the main package (nested serialization
regression, list handling,
toJsonLdStringenvelope, 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.