openapi3.Unmarshal broken: range can't iterate

The openapi3.Unmarshal function is currently not working.

The initial unmarshal seems to load the OpenAPI definition (it’s visible with debug.Dump), but attempting to iterate over the resulting data structure fails.

Here is a barebones example repo using the OpenAPI-Specification example API definition (the URL in Hugo’s docs is out of date) and the code examples in Hugo’s docs:

Running hugo server gives the error:

execute of template failed at <$api.Paths>: range can’t iterate over {map[] <nil> map[/pets:0xc000f8b8c0 /pets/{petId}:0xc000f8ba40]}

I ran into the same error when trying to work with other OpenAPI v3 definitions.

This worked prior to Hugo v0.121.0. The release notes for Hugo v0.121.0 state:

  • kin-openapi v0.122.0 has some minor breaking API changes which, from Hugo’s side of it, can be adapted by using the new .Map accessors if you get an error.

From the kin-openapi release notes (the link above):

  • openapi3.Paths went from map[string]*PathItem to a struct with an Extensions field and methods: Set, Value, Len, Map, and New*.

So change this:

{{ range $path, $details := $api.Paths }}

To this:

{{ range $path, $details := $api.Paths.Map }}
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.