netbox-community / go-netbox

The official Go API client for Netbox IPAM and DCIM service.
Other
199 stars 157 forks source link

Replace "go-swagger" by "openapi-generator" #157

Closed v0ctor closed 10 months ago

v0ctor commented 1 year ago

Since version 3.5, Netbox specifies its API with OpenAPI 3. Thus, it is no longer possible to keep this project up to date, as it is generated using go-swagger, a library that doesn't support OpenAPI 3 and has no intention to do so.

This PR replaces go-swagger by openapi-generator and rebuilds the library for the latest version of Netbox (3.5.8). This change is completely incompatible with previous versions of the library.

Note that this is a work in progress. I still didn't test the changes.

Any comments, suggestions or corrections are welcome! Furthermore, everyone is invited to participate in the OpenAPI 3 migration discussion.

jqueuniet commented 1 year ago

I've started testing this PR out and I'm running into troubles. There is some kind of reflection issue with filters on any list endpoint.

Misbehaving code samples:

vrflist, resp, err := client.IpamApi.
    IpamVrfsList(ctx).
    Name([]string{name}).
    Execute()

platformlist, resp, err := client.
    DcimApi.
    DcimPlatformsList(ctx).
    Slug([]string{slug}).
    Execute()

clspaglist, resp, err := client.VirtualizationApi.
    VirtualizationClustersList(ctx).
    SiteId([]*int32{&site.Id}).
    Status([]string{"active"}).
    Tag([]string{
        fmt.Sprintf("vnet_%s", vnet),
        fmt.Sprintf("env_%s", env),
        fmt.Sprintf("criticality_%s", criticality),
    }).
    Execute()

Resulting queries:

GET /api/ipam/vrfs/?name=reflect.Value+value HTTP/1.1

GET /api/dcim/platforms/?slug=reflect.Value+value HTTP/1.1

GET /api/virtualization/clusters/?site_id=reflect.Value+value&status=reflect.Value+value&tag=reflect.Value+value&tag=reflect.Value+value&tag=reflect.Value+value HTTP/1.1

No issue with retrieving objects by ID.

jqueuniet commented 1 year ago

Finished testing with my main workflows and other than this listing problem I did not run into any other issue. Everything seems to work fine for object creation, update and deletion

mytlogos commented 1 year ago

For the listing problem see https://github.com/OpenAPITools/openapi-generator/issues/14798 It should be already fixed on the openapi-master

jqueuniet commented 1 year ago

Thanks for the notice. Looking at the openapi-generator patch, it looks like the fix landed in 7.0.0, I can see the new .Interface() calls if I regenerate the client using this version.

v0ctor commented 1 year ago

Thank you very much to all for the feedback!

I've updated the PR to openapi-generator 7.0.1 and Netbox 3.6.2, and I've built the library with these changes.

I've not been able to test it yet, but seeing that openapi-generator 7+ is giving good results, it might be a good idea to release an alpha version.

jqueuniet commented 1 year ago

Just wanted to chime in to say I updated my working branch and now everything works fine.

tagur87 commented 11 months ago

Only issue I've found so far is this: https://github.com/netbox-community/go-netbox/discussions/156#discussioncomment-7958336 when enabling Enums. But other than that with the small workaround I found, it seems to work great!

v0ctor commented 10 months ago

It seems that this is finally the most viable option. I am doing some tests before releasing the first alpha version. See the comment in the discussion.

v0ctor commented 10 months ago

Finally, after five months, this PR is ready to be merged! 🥳