Skip to main content

Module schema_ref_resolver

Module schema_ref_resolver 

Source
Expand description

Build a JSON Schema validator that can resolve nested $ref pointers into the OpenAPI document’s #/components/schemas/... map.

Issue #79 round 18.3 — Srikanth’s vCenter run on 0.3.152 produced 157 violations like “Failed to create schema validator: Pointer ‘/components/schemas/Vcenter.VM.DiskCloneSpec’ does not exist”

Root cause: validate_request_body called jsonschema::options().build(&inner_schema_json) with only the inner schema as the validator’s document. When the schema’s properties contained nested "$ref": "#/components/schemas/X" strings, the validator tried to resolve them against the inner schema, which has no components section.

Fix: wrap the inner schema so it carries the spec’s components map at the document root, giving $ref pointers a place to resolve to. JSON Schema validators ignore unknown root keys, so the synthetic components field doesn’t affect validation semantics — it’s only there to be a resolution target.

Functions§

build_validator
Build a jsonschema::Validator for schema that can resolve $ref pointers against the full spec. Returns a String error so callers don’t have to thread jsonschema::ValidationError lifetimes through their result types.
merge_components_into
Merge the spec’s components into a root-level components key on the schema document. If the schema already declares a components key (rare but legal), it takes precedence — we don’t clobber explicit data. Returns the merged document.