Skip to main content

Module flatten

Module flatten 

Source
Expand description

JSON Schema reference bundling and inlining. Prepare $refs in a generated schema before it’s written to disk.

Fully inlined export mode is delegated to the jsonschema crate’s dereference helper, which sits on top of referencing — the same ref-resolution library that the broader JSON Schema validator ecosystem uses. This gives us battle-tested behaviour for every $ref shape we care about:

  • file refs with or without #/json/pointer fragments
  • URL refs with or without #/json/pointer fragments
  • bare fragment refs (#/$defs/foo) against the current document
  • RFC 6901 escapes (~0, ~1) inside pointers
  • relative-URI resolution against a base
  • JSON Schema drafts 4 through 2020-12 (we ship draft-07)
  • cycle detection (left in place as $ref strings rather than recursing forever)

All we own is the jsonschema::Retrieve implementation that maps URIs back to their content — files from the chart-local filesystem and URLs over HTTP via ureq, both gated by an explicit fetch policy.

Self-contained output mode keeps use sites as $refs but re-homes external documents under root-level $defs. For tests, the lower-level entry points accept any Retrieve impl so callers can wire in an in-memory map keyed by URI and avoid disk I/O entirely.

Functions§

bundle_prepared_refs
Validate and normalize already-prepared refs without allowing file/URL retrieval.
bundle_refs
Resolve external $refs into root-level $defs entries while preserving internal refs as refs.
bundle_with_retriever
Low-level bundling entry point for tests and custom retrievers.
flatten_prepared_refs
Fully inline already-prepared refs without allowing file/URL retrieval.
flatten_refs
Inline every $ref in schema against the filesystem rooted at base_dir.
flatten_with_retriever
Low-level dereference entry point: lets callers (most importantly, tests) plug in a custom Retrieve so they don’t have to touch the filesystem to exercise the ref-resolution behaviour.