Skip to main content

Crate schema_catalog

Crate schema_catalog 

Source
Expand description

§schema-catalog

Crates.io docs.rs GitHub License

Types for the JSON Schema catalog format (schema-catalog.json), compatible with SchemaStore.

Part of the Lintel project.

§Usage

use schema_catalog::{Catalog, parse_catalog};

let json = r#"{"version":1,"schemas":[{"name":"Example","description":"An example schema","url":"https://example.com/schema.json","fileMatch":["*.example.json"]}]}"#;
let catalog: Catalog = parse_catalog(json).unwrap();
assert_eq!(catalog.schemas[0].name, "Example");

§API

  • Catalog / SchemaEntry — serde types for the catalog format
  • parse_catalog(json) — deserialize a catalog from a JSON string
  • parse_catalog_value(value) — deserialize from a serde_json::Value
  • schema() — generate the JSON Schema for the Catalog type
  • CompiledCatalog::compile(&Catalog) — pre-compile all fileMatch globs into a fast matcher
  • CompiledCatalog::find_schema(path, file_name) — look up the schema URL for a file path
  • CompiledCatalog::find_schema_detailed(path, file_name) — look up with full match details

Bare filename patterns (e.g. tsconfig.json) are automatically expanded to also match nested paths (**/tsconfig.json). Negation patterns (starting with !) are skipped.

§Design

CompiledCatalog uses a single GlobMap from the glob-set crate. The GlobMap’s MatchEngine automatically dispatches each pattern to the fastest strategy (literal hash, extension hash, prefix/suffix tries, Aho-Corasick pre-filter).

This crate is #![no_std] — it only depends on alloc, serde, serde_json, schemars, and glob-set.

§License

Apache-2.0

Structs§

Catalog
Schema catalog index that maps file patterns to JSON Schema URLs.
CatalogGroup
A group of related schemas in the catalog.
CompiledCatalog
Compiled catalog for fast filename matching.
SchemaEntry
A single schema entry in the catalog.
SchemaMatch
Information about how a schema was matched from a catalog.

Constants§

DEFAULT_SCHEMA_URL
The default $schema URL for Lintel catalogs.

Functions§

parse_catalog
Parse a catalog from a JSON string.
parse_catalog_value
Parse a catalog from a serde_json::Value.
schema
Generate the JSON Schema for the Catalog type.