daveshanley / vacuum

vacuum is the worlds fastest OpenAPI 3, OpenAPI 2 / Swagger linter and quality analysis tool. Built in go, it tears through API specs faster than you can think. vacuum is compatible with Spectral rulesets and generates compatible reports.
https://quobix.com/vacuum
MIT License
488 stars 39 forks source link

Panic when I use an external reference as a request body. #486

Closed Keithwachira closed 2 months ago

Keithwachira commented 2 months ago

In my open api specification I use https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json as a ref in my schema for a request body. Something like below:

  requestBody:
    content:
      application/json:
        schema:
          $ref: "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json"

However this causes vacuum to panic.Here is the panic I get.

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

goroutine 8 [running]:
github.com/pb33f/libopenapi/index.(*Resolver).extractRelatives(0x140008e2140, 0x14000b68b00, 0x1400110c640, 0x1400110c3c0, 0x14000ec2a20?, {0x1400029c268, 0x1, 0x1}, 0x14000ebb9f8?, 0x0, ...)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi@v0.15.15/index/resolver.go:516 +0x2458
github.com/pb33f/libopenapi/index.(*Resolver).extractRelatives(0x140008e2140, 0x14000b68b00, 0x1400110c3c0, 0x1400110c280, 0x14000ec29f0?, {0x1400029c268, 0x1, 0x1}, 0x14000ebbdd8?, 0x0, ...)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi@v0.15.15/index/resolver.go:504 +0x480
github.com/pb33f/libopenapi/index.(*Resolver).extractRelatives(0x140008e2140, 0x14000b68b00, 0x1400110c280, 0x140007d15e0, 0x10500ac80?, {0x1400029c268, 0x1, 0x1}, 0x14000ebc1b8?, 0x0, ...)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi@v0.15.15/index/resolver.go:504 +0x480
github.com/pb33f/libopenapi/index.(*Resolver).extractRelatives(0x140008e2140, 0x14000b68b00, 0x140007d15e0, 0x0, 0x10500ac80?, {0x1400029c268, 0x1, 0x1}, 0x0?, 0x0, ...)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi@v0.15.15/index/resolver.go:504 +0x480
github.com/pb33f/libopenapi/index.(*Resolver).VisitReference(0x140008e2140, 0x14000b68b00, 0x0?, {0x0?, 0x0?, 0x0?}, 0x0)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi@v0.15.15/index/resolver.go:338 +0x158
github.com/pb33f/libopenapi/index.visitIndexWithoutDamagingIt(0x140008e2140, 0x1400027f400)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi@v0.15.15/index/resolver.go:250 +0xd0
github.com/pb33f/libopenapi/index.(*Resolver).CheckForCircularReferences(0x140008e2140)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi@v0.15.15/index/resolver.go:219 +0x28
github.com/pb33f/libopenapi/index.(*Rolodex).CheckForCircularReferences(0x1400009a1a0)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi@v0.15.15/index/rolodex.go:358 +0x44
github.com/pb33f/libopenapi/datamodel/low/v3.createDocument(0x140004d4000, 0x140005aa000)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi@v0.15.15/datamodel/low/v3/create_document.go:115 +0x658
github.com/pb33f/libopenapi/datamodel/low/v3.CreateDocumentFromConfig(...)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi@v0.15.15/datamodel/low/v3/create_document.go:28
github.com/pb33f/libopenapi.(*document).BuildV3Model(0x14000e4b9c0)
        /home/runner/go/pkg/mod/github.com/pb33f/libopenapi@v0.15.15/document.go:316 +0xa8
github.com/daveshanley/vacuum/cmd.lintFile({{0x16bdf756c, 0xc}, {0x0, 0x0}, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, ...})
        /home/runner/work/vacuum/vacuum/cmd/lint.go:309 +0x1ac
github.com/daveshanley/vacuum/cmd.GetLintCommand.func2.1(0x140004208c0?, 0x0, {0x16bdf756c, 0xc})
        /home/runner/work/vacuum/vacuum/cmd/lint.go:218 +0x278
created by github.com/daveshanley/vacuum/cmd.GetLintCommand.func2 in goroutine 1
        /home/runner/work/vacuum/vacuum/cmd/lint.go:185 +0x141c
daveshanley commented 2 months ago

Nice catch, thank you for reporting this.. will fix asap.

Keithwachira commented 2 months ago

Nice catch, thank you for reporting this.. will fix asap.

Thank you for the quick reply

daveshanley commented 2 months ago

This has been resolved in 0.9.15.

A test has been added to validate: https://github.com/daveshanley/vacuum/blob/main/motor/rule_applicator_test.go#L2283

Keithwachira commented 2 months ago

This has been resolved in 0.9.15.

A test has been added to validate: https://github.com/daveshanley/vacuum/blob/main/motor/rule_applicator_test.go#L2283

This has been resolved in 0.9.15.

A test has been added to validate: https://github.com/daveshanley/vacuum/blob/main/motor/rule_applicator_test.go#L2283

Thank you so much for the quick fix.