rules_xsd
Bazel rules for XSD: offline schema validation + XSD→RDF/OWL vocabulary generation.
| Latest | 0.0.1 |
|---|---|
| Versions | 1 |
| Category | Bazel rules |
| Maintainers | Matt Marshall |
| Registry | https://registry.tbzl.dev/modules/rules_xsd/ |
| Source | github.com/tomato-bazel/rules_xsd |
bazel_dep(name = "rules_xsd", version = "0.0.1")
View source & releases on GitHub ↗
Bazel rules for XSD: offline schema validation + XSD→RDF/OWL vocabulary generation (the rules_xsd seed lifted from uslm).
Status: v0.0.1 — scaffold
No public surface yet. See CHANGELOG.md for what has shipped.
Install
.bazelrc:
common --registry=https://registry.fastverk.com/
common --registry=https://bcr.bazel.build/
MODULE.bazel:
bazel_dep(name = "rules_xsd", version = "0.0.1") Usage#
Real usage, taken from the module’s examples/.
examples/BUILD.bazel
load("//xsd:defs.bzl", "xsd_schema", "xsd_to_vocab", "xsd_validate_test")
package(default_visibility = ["//visibility:public"])
# A two-schema closure: person.xsd imports common.xsd by namespace. The import's
# schemaLocation is a remote URL that is never fetched — xsd_validate resolves it
# from this local closure (matched on targetNamespace), so the gate is offline.
xsd_schema(
name = "common",
srcs = ["common.xsd"],
)
xsd_schema(
name = "person",
srcs = ["person.xsd"],
deps = [":common"],
)
# Gate: the instance validates against the person schema + its closure.
xsd_validate_test(
name = "person_valid",
schema = ":person",
xml = "person.xml",
)
# XSD → RDF/OWL: generate a Turtle vocabulary (person → owl:Class, id → property).
xsd_to_vocab(
name = "person_vocab",
namespace = "https://example.org/person#",
schema = ":person",
)Rules & providers#
Generated with Stardoc from the module's .bzl sources.
from docs/defs.md
User-facing XSD rules (the rules_xsd seed).
Two rules, deliberately shaped like rules_rdf’s rdf_dataset + rdf_validate_test
so the whole package lifts into a standalone rules_xsd ruleset once the shape
settles (legislative-kg §11):
-
xsd_schema(name, srcs, deps)— declare an XSD plus the schemas it imports (as otherxsd_schematargets). ProducesXsdInfocarrying the transitive import closure, the XSD analog of anrdf_datasetclosure. -
xsd_validate_test(name, schema, xml)— assert an XML instance validates against anXsdInfo’s schema (resolving every<xsd:import>from the local closure, never the network). The first correct-by-construction gate.
load("//xsd:defs.bzl", "xsd_schema", "xsd_validate_test")
xsd_schema(name = "xml_ns", srcs = ["@uslm_schema//:xml.xsd"])
xsd_schema(name = "uslm", srcs = ["@uslm_schema//:USLM-1.0.15.xsd"], deps = [":xml_ns", ...])
xsd_validate_test(name = "slice_valid", schema = ":uslm", xml = "//data:usc_t26_slice.xml")
Next step (the owl:imports-strict-manifest analog): an aspect that parses each
schema’s <xsd:import namespace=…> and fails unless every imported namespace is
covered by a declared dep’s targetNamespace — a closure-completeness gate.
For the first cut, deps are explicit and the validator fails loudly if a needed
namespace is absent from the closure.
xsd_schema
load("@rules_xsd//xsd:defs.bzl", "xsd_schema")
xsd_schema(name, deps, srcs, root)
Declare an XSD schema + its transitive import closure.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Imported schemas (other xsd_schema targets); their closures fold into this one’s transitive_files. | List of labels | optional | [] |
| srcs | This schema’s own .xsd file(s). | List of labels | required | |
| root | Entry-point schema to validate / generate against (defaults to srcs[0]). | Label | optional | None |
xsd_to_vocab
load("@rules_xsd//xsd:defs.bzl", "xsd_to_vocab")
xsd_to_vocab(name, namespace, schema)
Generate a Turtle RDF/OWL vocabulary from an XSD — the ‘XSD -> RDF, first instance’. Feed the output to jena_schemagen for typed views.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| namespace | Ontology namespace IRI for the generated terms (defaults to the schema’s targetNamespace + ’#’). | String | optional | "" |
| schema | The xsd_schema whose root is translated to an RDF/OWL vocabulary. | Label | required |
xsd_validate_test
load("@rules_xsd//xsd:defs.bzl", "xsd_validate_test")
xsd_validate_test(name, schema, xml)
Assert an XML instance validates against an XSD closure (offline).
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| schema | The xsd_schema to validate against (its closure resolves imports). | Label | required | |
| xml | The XML instance to validate. | Label | required |
from docs/providers.md
Providers for the generic XSD layer (the rules_xsd seed).
XsdInfo is the XSD analog of rules_rdf’s RdfDatasetInfo: a schema plus the
transitive closure of the schemas it imports, so a validator (or, later, an
XSD→emitter generator) sees the whole closure with no network access. An XSD is
rarely standalone — USLM-1.0 imports XML, Dublin Core terms, and XHTML — so the
closure is first-class, exactly as RDF graphs carry their owl:imports closure.
XsdInfo
load("@rules_xsd//xsd:providers.bzl", "XsdInfo")
XsdInfo(schema_root, transitive_files)
A declared XSD schema and its transitive import closure.
FIELDS
Conformance#
No gate findings. 10 contested atoms. See how gating works or the full report.
Contested atoms
Third-party modules where this module resolves a different version than others do. Not a violation of anything this module did — it is the actionable form of a registry-level convergence finding, and the sentence a maintainer can act on.
| Atom | Resolved here | Elsewhere |
|---|---|---|
apple_support | 1.24.2 | 2.2.0 ×1 |
bazel_skylib | 1.8.2 | 1.9.0 ×2 |
gazelle | 0.36.0 | 0.30.0 ×50.44.0 ×10.51.0 ×3 |
nlohmann_json | 3.6.1 | 3.12.0.bcr.1 ×1 |
protobuf | 33.4 | 34.0.bcr.1 ×2 |
rules_go | 0.60.0 | 0.39.1 ×5 |
rules_jvm_external | 6.7 | 6.8 ×4 |
rules_python | 1.7.0 | 2.0.1 ×1 |
rules_swift | 3.1.2 | 3.6.1 ×1 |
upb | 0.0.0-20220923-a547704 | 0.0.0-20230516-61a97ef ×1 |
Dependencies#
Depends on
Versions#
1 published version, newest first. Each resolves to an immutable, integrity-checked archive.
| Version | Integrity (sha256) | Source archive |
|---|---|---|
0.0.1 latest | xvqoq60YXcIhNxlq… | tag archive ↗ |
Changelog#
All notable changes to rules_xsd. The format is loosely Keep a Changelog — version headers mirror the published bazel-registry entries.
0.0.1 — scaffold
- Initial scaffold via
rels scaffold. No public API yet.