Skip to main content

Crate schemastore

Crate schemastore 

Source
Expand description

§schemastore

Crates.io docs.rs GitHub License

Parse and match files against the SchemaStore catalog.

SchemaStore is a community-maintained collection of JSON Schema definitions for common configuration files. This crate deserializes the catalog and matches file paths to their corresponding schemas using the fileMatch glob patterns.

§Usage

use schemastore::{parse_catalog, CompiledCatalog, CATALOG_URL};

// Fetch the catalog JSON yourself (using reqwest, ureq, etc.)
// let json = reqwest::blocking::get(CATALOG_URL)?.text()?;
// let value: serde_json::Value = serde_json::from_str(&json)?;
// let catalog = parse_catalog(value)?;

// Example with inline data:
let value = serde_json::json!({
    "version": 1,
    "schemas": [{
        "name": "TypeScript",
        "description": "TypeScript compiler configuration",
        "url": "https://json.schemastore.org/tsconfig.json",
        "fileMatch": ["tsconfig.json"]
    }]
});
let catalog = parse_catalog(value).unwrap();
let compiled = CompiledCatalog::compile(&catalog);

assert!(compiled.find_schema("tsconfig.json", "tsconfig.json").is_some());

§API

  • CATALOG_URL — the well-known URL for the SchemaStore catalog JSON
  • parse_catalog(Value) — deserialize the catalog from a serde_json::Value
  • CompiledCatalog::compile(&Catalog) — pre-compile all fileMatch globs
  • CompiledCatalog::find_schema(path, file_name) — look up the schema URL for a file path

Catalog types (Catalog, SchemaEntry, etc.) live in the schema-catalog crate.

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

§Design

This crate is #![no_std] — it only depends on alloc, serde, serde_json, and glob-match. No HTTP client is included; callers fetch the catalog JSON themselves.

§License

Apache-2.0

Structs§

CompiledCatalog
Compiled catalog for fast filename matching.
SchemaMatch
Information about how a schema was matched from a catalog.

Constants§

CATALOG_URL
The URL of the SchemaStore catalog.

Functions§

parse_catalog
Parse a SchemaStore catalog from a serde_json::Value.