Skip to content

BuildV3Model returns a partially-built model that panics on public API #616

Description

@AtanasovskiPetar

Version: reproduced on v0.38.5 and v0.38.7

If one operation in a path item fails to build, BuildV3Model still returns a model along with the error. The other operations in that path item never get built, so they come back as empty low Operation structs with a nil embedded *low.Reference.

Calling IsReference() on one of those panics with a nil pointer dereference, so one bad $ref can take down anything that walks the model. The $ref error itself is fine, it's the state of the model returned with it that's the problem.

Different from #585.

Reproducer — two operations, only get has the dangling $ref

openapi: 3.0.2
info: { title: t, version: 1.0.0 }
paths:
  /p:
    get:
      responses:
        '200':
          description: ok
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Nope' }
    post:
      responses:
        '200': { description: ok }
model, errs := doc.BuildV3Model()
pi, _ := model.Model.Paths.PathItems.Get("/p")

pi.Get.GoLow().RootNode == nil
pi.Post.GoLow().RootNode == nil
pi.Post.GoLow().IsReference()       // panic: nil pointer dereference

It needs two or more operations in the same path item — a single-operation path item does not reproduce it.

We hit this through daveshanley/vacuum, which walks the model with pb33f/doctor; it panics at doctor/model/high/v3/operation.go:261.

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