pb33f / libopenapi

libopenapi is a fully featured, high performance OpenAPI 3.1, 3.0 and Swagger parser, library, validator and toolkit for golang applications.
https://pb33f.io/libopenapi/
Other
487 stars 64 forks source link

Example not compiling due to error: cannot range over docModel.Model.Paths.PathItems #304

Closed ajb-neodynamics-io closed 5 months ago

ajb-neodynamics-io commented 5 months ago

I'm following the example illustrated here: https://quobix.com/articles/parsing-openapi-using-go/

But I'm running into an issue where I'm getting a compile error: internal/config/config.go:131:34: cannot range over docModel.Model.Paths.PathItems (variable of type *"github.com/pb33f/libopenapi/orderedmap".Map[string, *"github.com/pb33f/libopenapi/datamodel/high/v3".PathItem])

The code I'm attempting to run is exactly the same as the code in the tutorial. I literally cut and paste it:

image

Any idea why I continue to get the following error:

image

MacOS version Sonoma 14.5 Go version 1.22 libopenapi version 0.16.8

ajb-neodynamics-io commented 5 months ago

I though it may be because the petstorev3.json file that the tutorial prompts you to download is actually written in yaml, but changing the extension to .yaml did not work, same error.

ajb-neodynamics-io commented 5 months ago

Trying another example from the "Installing" section of the guide works as expected:

image

And I get the expected result:

image

But when I try to range over the v3Model.Model.Paths.PathItems I get the same error as in my first post.

daveshanley commented 5 months ago

Hi There, This is the same issue as #263

I need to update my blog is the correct answer - the API changed a while back and it means we now use ordered maps, instead of a regular map. This allows us to keep ordering in place when re-rendering the spec back out.

I will now go and update my blog however.

daveshanley commented 5 months ago

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

Thank you for the nudge!