libopenapi icon indicating copy to clipboard operation
libopenapi copied to clipboard

example for documentation doesn't work?

Open ScopeSV opened this issue 11 months ago • 4 comments

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?

ScopeSV avatar Mar 01 '24 21:03 ScopeSV

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.

daveshanley avatar Mar 02 '24 14:03 daveshanley

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

daveshanley avatar Mar 02 '24 15:03 daveshanley

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 :-)

ScopeSV avatar Mar 02 '24 16:03 ScopeSV

I am keeping this open until I update the blog.

daveshanley avatar Mar 06 '24 13:03 daveshanley

OK. I updated the blog! The example code is using the new API and I added some notes.

daveshanley avatar Jun 24 '24 14:06 daveshanley