Skip to content

v0.14.0: response validation fails with "schema node was not found in its root document" for multi-file specs (inline schemas with cross-file $refs) #314

Description

@vibexp-gh

Regression in v0.14.0

After upgrading from v0.13.10 to v0.14.0, ValidateHttpResponse fails at schema-compile time for any operation whose response schema is an inline schema (in an externally-referenced path file) that contains cross-file $refs — a layout used by multi-file OpenAPI projects (e.g. openapi.yaml + paths/*.yaml + schemas/*.yaml).

The error:

200 response body for '/inline-oneof' failed schema compilation: The response schema for status code '200' failed to compile: schema node was not found in its root document

It comes from buildSchemaDocumentResourcesjsonPointerForNode(schemaIndex.GetRootNode(), schema.GoLow().GetRootNode()) in schema_validation/schema_resources.go: the pointer walk can't locate the schema's YAML node in the index root document.

Minimal repro

openapi.yaml:

openapi: 3.1.0
info:
  title: repro
  version: 1.0.0
paths:
  /direct-ref:
    $ref: './paths/direct.yaml#/p'
  /inline-oneof:
    $ref: './paths/inline.yaml#/p'
components:
  schemas:
    Widget:
      type: object
      properties:
        name:
          type: string

paths/direct.yaml:

p:
  get:
    responses:
      '200':
        description: ok
        content:
          application/json:
            schema:
              $ref: '../openapi.yaml#/components/schemas/Widget'

paths/inline.yaml:

p:
  get:
    responses:
      '200':
        description: ok
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '../openapi.yaml#/components/schemas/Widget'
                - type: object
                  properties:
                    other:
                      type: string

Validation code:

doc, _ := libopenapi.NewDocumentWithConfiguration(raw, &datamodel.DocumentConfiguration{
    BasePath:            filepath.Dir(specPath),
    SpecFilePath:        specPath,
    AllowFileReferences: true,
})
model, _ := doc.BuildV3Model()
v := validator.NewValidatorFromV3Model(&model.Model)
ok, errs := v.ValidateHttpResponse(req, resp) // req: GET /inline-oneof, body {name:x}

Observed (v0.14.0)

case result
/direct-ref (response schema is a bare cross-file $ref) ✅ ok
/inline-oneof (inline oneOf with cross-file $refs) ❌ schema node was not found in its root document
inline allOf with cross-file $refs (same layout) ❌ same error
inline type: array / items: {$ref: cross-file} in a path file ❌ same error
same compositions moved into components/schemas with file-internal refs ✅ ok

On v0.13.10 all of these pass.

Also possibly related: an allOf defined in an external schema file (./schemas/foo.yaml#/Bar) whose members reference another component in the root document (../openapi.yaml#/components/schemas/Baz) hits the same compile error when reached through a path-level reference.

v0.14.0, libopenapi v0.38.7, go 1.25.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions