libopenapi
libopenapi copied to clipboard
example for documentation doesn't work?
Hi. Im checking out some different solutions for parsing and reading open api, and found your library. However when testing it with the example, it didn't work.
From the example:
paths := len(v3Model.Model.Paths.PathItems)
schemas := len(v3Model.Model.Components.Schemas)
These are pointers, and cannot be checked length on. However I found that they both have a Len method:
v3Model.Model.Components.Schemas.Len()
I didnt find a way to iterate over the paths, but I found this blog post https://quobix.com/articles/parsing-openapi-using-go/ Which does not work, as they are pointers. Couldn't find any iterating methods on the structs either.
Has there been an update lately that may have broken the documentation?
This is a good call out, there have been some major upgrades since that blog post was written - I need to update it.
Check the docs on https://pb33f.io/libopenapi/ for up to date examples.
Check out the updated docs here: https://pb33f.io/libopenapi/model/
And there are working examples here: https://github.com/pb33f/libopenapi/blob/main/document_examples_test.go
Looks good! Thank you very much.
Ive spent some times working with the library and reading on every method and I came up with a similar solution for traversing the openapi, so im happy that was the proper way of doing it :-)
I am keeping this open until I update the blog.
OK. I updated the blog! The example code is using the new API and I added some notes.