Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic in BuildV3Model when certain keywords (allOf, anyOf) are required properties #385

Closed
PhilippHeuer opened this issue Mar 2, 2025 · 2 comments

Comments

@PhilippHeuer
Copy link

Description

I ran into a panic when certain names (e.g. allOf, anyOf) are set as required properties with v0.21.7.

required:
  - allOf

The panic occurs on the BuildV3Model call:

panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
github.com/pb33f/libopenapi/index.(*Resolver).extractRelatives(0xc000140000, 0xc000128000, 0xc00029afa0, 0xc00029ae60, 0xc0002e4bd8, {0xc00012a048, 0x1, 0x1}, 0xc0002e4a90, 0x0, ...)
        /home/user/go/pkg/mod/github.com/pb33f/libopenapi@v0.21.7/index/resolver.go:756 +0x230a
github.com/pb33f/libopenapi/index.(*Resolver).extractRelatives(0xc000140000, 0xc000128000, 0xc00029ae60, 0x0, 0xc0002e4bd8, {0xc00012a048, 0x1, 0x1}, 0xc0002e4a90, 0x0, ...)
        /home/user/go/pkg/mod/github.com/pb33f/libopenapi@v0.21.7/index/resolver.go:508 +0x59f
github.com/pb33f/libopenapi/index.(*Resolver).VisitReference(0xc000140000, 0xc000128000, 0xc0002e4bd8, {0x0?, 0x137ec0d1aee9?, 0xc0002e4b58?}, 0x0)
        /home/user/go/pkg/mod/github.com/pb33f/libopenapi@v0.21.7/index/resolver.go:338 +0x1ee
github.com/pb33f/libopenapi/index.visitIndexWithoutDamagingIt(0xc000140000, 0xc000286588)
        /home/user/go/pkg/mod/github.com/pb33f/libopenapi@v0.21.7/index/resolver.go:258 +0x23b
github.com/pb33f/libopenapi/index.(*Resolver).CheckForCircularReferences(0xc000140000)
        /home/user/go/pkg/mod/github.com/pb33f/libopenapi@v0.21.7/index/resolver.go:219 +0x2a
github.com/pb33f/libopenapi/index.(*Rolodex).CheckForCircularReferences(0xc000294340)
        /home/user/go/pkg/mod/github.com/pb33f/libopenapi@v0.21.7/index/rolodex.go:423 +0x47
github.com/pb33f/libopenapi/datamodel/low/v3.createDocument(0xc00029c0b0, 0xc0002a0000)
        /home/user/go/pkg/mod/github.com/pb33f/libopenapi@v0.21.7/datamodel/low/v3/create_document.go:119 +0x91f
github.com/pb33f/libopenapi/datamodel/low/v3.CreateDocumentFromConfig(...)
        /home/user/go/pkg/mod/github.com/pb33f/libopenapi@v0.21.7/datamodel/low/v3/create_document.go:30
github.com/pb33f/libopenapi.(*document).BuildV3Model(0xc0002bc0c0)

Test-Case to Reproduce

func TestRequiredPanic(t *testing.T) {
	spec := `
openapi: 3.0.1
info:
  title: Test
  version: 1.0.0
paths:
  /endpoint:
    get:
components:
  schemas:
    ExampleSchema:
      required:
        - allOf
      type: object
      properties:
        allOf:
          type: string
`
	doc, err := libopenapi.NewDocument([]byte(spec))
	assert.NoError(t, err)
	assert.NotNil(t, doc)

	v3Model, errs := doc.BuildV3Model() // panic occurs here
	assert.Empty(t, errs)
	assert.NotNil(t, v3Model)
}
@daveshanley
Copy link
Member

Damn, I saw this myself in the wild the other day. Will fix.

@daveshanley
Copy link
Member

This has been fixed in v0.21.8

This bug literally blew up the doctor and left it dead for hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants