mix schema_org.build_types (SchemaOrg v0.2.0)

Copy Markdown View Source

Regenerates the SchemaOrg.* type modules from the official Schema.org JSON-LD graph.

This task is for library maintainers only. It is not part of the runtime and is not shipped in the Hex package. It reads the vendored graph, maps every Property onto the Classes in its domainIncludes (plus inherited Classes via subClassOf), and renders one Elixir module per Class through an EEx template.

mix schema_org.build_types
mix schema_org.build_types --file priv/schemaorg-current-https.jsonld --out lib/schema_org/types

Options

  • --file - path to the Schema.org JSON-LD graph (default: priv/schemaorg-current-https.jsonld)
  • --out - output directory for generated modules (default: lib/schema_org/types)

Download the graph with:

curl -L https://schema.org/version/latest/schemaorg-current-https.jsonld \
  -o priv/schemaorg-current-https.jsonld

Summary

Functions

Transitive ancestor class ids of class_id, cycle-safe.

Turns a decoded JSON-LD graph into a sorted list of module specs, each ready to render: %{module_name, schema_type, moduledoc, filename, properties}.

Normalises an rdfs:comment (string, list, or @value map) to clean Markdown.

Builds the render descriptor for a single property node.

Builds %{class_id => [property_id, ...]} from each property's domainIncludes.

Maps a Schema.org property local name to a snakecase field name, suffixing any Elixir keyword with `(e.g."dateModified":datemodified,"in":in`).

Strips the schema: prefix from an @id (e.g. "schema:Product""Product").

Maps a Schema.org local name to a valid Elixir module alias.

Normalises a polymorphic Schema.org field into a flat list of id strings.

Builds %{class_id => [parent_class_id, ...]} from each class's subClassOf.

Splits the graph's @graph into {classes, properties}.

All property ids valid on a class: its own (via domainIncludes) plus every property inherited from a transitive subClassOf ancestor. Deduplicated.

Renders a module spec to formatted Elixir source via the EEx template.

Functions

ancestors(class_id, parents)

Transitive ancestor class ids of class_id, cycle-safe.

build_modules(graph)

Turns a decoded JSON-LD graph into a sorted list of module specs, each ready to render: %{module_name, schema_type, moduledoc, filename, properties}.

class?(node)

comment_text(text)

Normalises an rdfs:comment (string, list, or @value map) to clean Markdown.

Schema.org comments embed raw HTML (<p>, <br/>, <a href>, <code>) and [[wiki]] cross-references. Left as-is they render badly — and an unbalanced tag makes ExDoc emit "Failed to find closing <p>". This converts the useful markup to Markdown and strips the rest so generated @moduledocs are clean.

descriptor(prop)

Builds the render descriptor for a single property node.

direct_properties(properties)

Builds %{class_id => [property_id, ...]} from each property's domainIncludes.

field_name(local)

Maps a Schema.org property local name to a snakecase field name, suffixing any Elixir keyword with `(e.g."dateModified":datemodified,"in":in`).

local_name(id)

Strips the schema: prefix from an @id (e.g. "schema:Product""Product").

module_name(local)

Maps a Schema.org local name to a valid Elixir module alias.

PascalCase names pass through. A leading-lowercase name is capitalised. Names that are not valid aliases (e.g. "3DModel", which starts with a digit) are prefixed with Type and stripped of non-alphanumerics — while schema_type keeps the exact original, so the emitted JSON-LD @type stays correct.

normalize_list(list)

Normalises a polymorphic Schema.org field into a flat list of id strings.

Handles all four shapes the spec uses interchangeably: nil (absent), a bare string (e.g. an @type value), a single %{"@id" => id} object, and a list of any of the above.

parent_map(classes)

Builds %{class_id => [parent_class_id, ...]} from each class's subClassOf.

partition_graph(graph)

Splits the graph's @graph into {classes, properties}.

property?(node)

property_ids_for_class(class_id, direct, parents)

All property ids valid on a class: its own (via domainIncludes) plus every property inherited from a transitive subClassOf ancestor. Deduplicated.

render_module(template, spec)

Renders a module spec to formatted Elixir source via the EEx template.

Raises if the generated code is not valid Elixir (the format pass parses it), which surfaces template/sanitiser bugs immediately instead of writing junk.