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::Validatorforschemathat can resolve$refpointers against the fullspec. Returns aStringerror so callers don’t have to threadjsonschema::ValidationErrorlifetimes through their result types. - merge_
components_ into - Merge the spec’s components into a root-level
componentskey on the schema document. If the schema already declares acomponentskey (rare but legal), it takes precedence — we don’t clobber explicit data. Returns the merged document.