pb33f / openapi-changes

The world's sexiest OpenAPI breaking changes detector. Discover what changed between two OpenAPI specs, or a single spec over time. Supports OpenAPI 3.1, 3.0 and Swagger
https://pb33f.io/openapi-changes/
Other
180 stars 16 forks source link

Crash on Summary if Starting Document Has no Components #130

Open DapperMongoose opened 5 months ago

DapperMongoose commented 5 months ago

Hello again, still a big fan of these tools!

I've discovered that if the spec you start from lacks a components property and then you compare with a spec that has components added, running the summary command will cause a crash. Adding an empty components property to the starting spec fixes the problem.

Interestingly enough HTML report generation seems to work correctly without the empty property.

Here's a zip file with some minimal reproduction specs: examples.zip (Note: adding an empty components property to the new file will also cause the crash but I've added a mock schema to be more correct to the real use case that produced the error)

And here is the command and result of running against the attached files:

openapi-changes summary start-spec.yaml compare-spec.yaml 

@@@@@@@   @@@@@@@   @@@@@@   @@@@@@   @@@@@@@@
@@@@@@@@  @@@@@@@@  @@@@@@@  @@@@@@@  @@@@@@@@
@@!  @@@  @@!  @@@      @@@      @@@  @@!
!@!  @!@  !@   @!@      @!@      @!@  !@!
@!@@!@!   @!@!@!@   @!@!!@   @!@!!@   @!!!:!
!!@!!!    !!!@!!!!  !!@!@!   !!@!@!   !!!!!:
!!:       !!:  !!!      !!:      !!:  !!:
:!:       :!:  !:!      :!:      :!:  :!:
 ::        :: ::::  :: ::::  :: ::::   ::
 :        :: : ::    : : :    : : :    :

🔗 https://pb33f.io/openapi-changes/
------------------------------------
openapi-changes version: 0.0.62 | compiled: Thu, 25 Apr 2024 16:39:09 UTC

▀  Building original model for commit ef697c
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xb2c22a]

goroutine 1 [running]:
github.com/pb33f/openapi-changes/cmd.generateTreeState(0xc000404230, 0xe0?)
        /home/runner/work/openapi-changes/openapi-changes/cmd/tree.go:192 +0x32a
github.com/pb33f/openapi-changes/cmd.buildConsoleTreeNode(0xc000451440, {0xc066e0, 0xc000410100}, 0x0, 0x0)
        /home/runner/work/openapi-changes/openapi-changes/cmd/tree.go:36 +0x2afa
github.com/pb33f/openapi-changes/cmd.buildConsoleTree(0xc000451546?, 0x0)
        /home/runner/work/openapi-changes/openapi-changes/cmd/tree.go:205 +0x54
github.com/pb33f/openapi-changes/cmd.printSummaryDetails({0xc00040aff0, 0x2, 0xc000451a90?}, 0x0)
        /home/runner/work/openapi-changes/openapi-changes/cmd/summary.go:418 +0x40c
github.com/pb33f/openapi-changes/cmd.runLeftRightSummary({0x7ffd7e80916a, 0xf}, {0x7ffd7e80917a, 0x11}, 0xc00028c060, 0xc00028c0c0, {0x0, 0x0}, 0x1, 0x0)
        /home/runner/work/openapi-changes/openapi-changes/cmd/summary.go:345 +0x91a
github.com/pb33f/openapi-changes/cmd.GetSummaryCommand.func1(0xc000178608, {0xc00012c5e0, 0x2, 0xd38f0b?})
        /home/runner/work/openapi-changes/openapi-changes/cmd/summary.go:236 +0x717
github.com/spf13/cobra.(*Command).execute(0xc000178608, {0xc00012c580, 0x2, 0x2})
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0x17b2420)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/pb33f/openapi-changes/cmd.Execute({0x113f42c?, 0x19?}, {0x1149940?, 0xd4767a?}, {0xc00012a640?, 0xc0000061c0?})
        /home/runner/work/openapi-changes/openapi-changes/cmd/root.go:51 +0x91
main.main()
        /home/runner/work/openapi-changes/openapi-changes/openapi-changes.go:29 +0x158
daveshanley commented 5 months ago

Oh dear, willfix.