openapi-changes
openapi-changes copied to clipboard
"segmentation violation" on circular reference used
Hello. Here is the minimal example to reproduce the issue:
{
"openapi": "3.1.0",
"components": {
"schemas": {
"BadCircularElement": {
"$ref": "#/components/schemas/BadCircularElement"
},
"ElementWithUsage": {
"type": "object",
"properties": {
"somProp": {
"oneOf": [
{
"type": "null"
},
{
"items": {
"$ref": "#/components/schemas/BadCircularElement"
},
"type": "array"
}
]
}
}
}
}
}
}
openapi-changes summary openapi.json openapi.json will fail with the following error:
openapi-changes version: 0.0.76 | compiled: Wed, 26 Feb 2025 01:54:49 UTC
▀ starting work. (0s)panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x104cb17c4]
goroutine 182 [running]:
github.com/pb33f/libopenapi/index.(*CircularReferenceResult).GenerateJourneyPath(0x14000211ae0?)
/home/runner/go/pkg/mod/github.com/pb33f/[email protected]/index/circular_reference_result.go:24 +0x24
github.com/pb33f/libopenapi/datamodel/low.LocateRefNodeWithContext({0x1056ff0b0, 0x14000298330}, 0x140002486e0, 0x14000254008)
/home/runner/go/pkg/mod/github.com/pb33f/[email protected]/datamodel/low/extraction_functions.go:100 +0x310
github.com/pb33f/libopenapi/datamodel/low/base.buildSchema({0x1056ff0b0, 0x14000298330}, 0x1400062f960, 0x14000248640, 0x140002486e0, 0x1400062f7a0, 0x14000254008)
/home/runner/go/pkg/mod/github.com/pb33f/[email protected]/datamodel/low/base/schema.go:1201 +0x34c
created by github.com/pb33f/libopenapi/datamodel/low/base.(*Schema).Build in goroutine 106
/home/runner/go/pkg/mod/github.com/pb33f/[email protected]/datamodel/low/base/schema.go:891 +0x2c94
At the same time vacuum tool will report the problem with no panic `./vacuum lint -b -d -e openapi.json:
/Users/user/Downloads/openapi.json
----------------------------------
Location | Severity | Message | Rule | Category | Path
openapi.json:4:20 | error | infinite circular reference detected: BadCircularElement: BadCircularElement -> ... | resolving-references | Schemas | BadCircularElement -> BadCircularElement
openapi.json:5:13 | error | build schema failed: circular reference 'BadCircularElement -> BadCircularElemen... | schema-build-failure | Schemas | $.components.schemas['BadCircularElement']
openapi.json:17:33 | error | build schema failed: circular reference 'BadCircularElement -> BadCircularElemen... | schema-build-failure | Schemas | $.components.schemas['ElementWithUsage'].properties['somProp...
Oh dear, this is actually a bug in libopenapi (github.com/pb33f/libopenapi/). Willfix.
This sounds a bit surprising, since vacuum is also using libopenapi 😯 UPD: Oh, I should've read the stacktrace 🤦🏻♂️
libopenapi is still pre v1, it's got some glitches still that need working out before we hit that milestone :)
This is resolved in v0.0.79