mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 12:37:48 +00:00
fix: panic thrown when paths is wrapped in an array #4
When paths are wrapped in an array, the index throws an error because it's expecting them to be supplied as a map. Now paths can be wrapped or unwrapped, the index won't care.
This commit is contained in:
@@ -360,3 +360,30 @@ info:
|
||||
// license:
|
||||
// url: https://pb33f.io/license
|
||||
}
|
||||
|
||||
func TestDocument_Panic(t *testing.T) {
|
||||
|
||||
// How to mutate values in an OpenAPI Specification, without re-ordering original content.
|
||||
|
||||
// create very small, and useless spec that does nothing useful, except showcase this feature.
|
||||
spec := `{
|
||||
"openapi": "3.1.0",
|
||||
"paths": [
|
||||
"/": {
|
||||
"get": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
// create a new document from specification bytes
|
||||
doc, err := NewDocument([]byte(spec))
|
||||
|
||||
// if anything went wrong, an error is thrown
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("cannot create new document: %e", err))
|
||||
}
|
||||
|
||||
// because we know this is a v3 spec, we can build a ready to go model from it.
|
||||
v3Model, errors := doc.BuildV3Model()
|
||||
fmt.Print(v3Model, errors)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user