Closed SchwarzM closed 6 years ago
When I originally started building this, I didn't realize it was possible. If you could come up with something that generates reasonably nice code (or can be easily wrapped in a good API), I'd be in favor of doing so.
I played with this some more: https://github.com/SchwarzM/go-netbox
The current swagger.json has all api calls but lacks proper definitions for responses maybe we could present this to @jeremystretch if this was left out on purpose or if he would be open for some swagger annotation tweaks to make go-netbox's life easier.
The generated client is not usable due to the models missing but is clearly shows the outcome of a swagger generation.
Kind regards SchwarzM
I need another chunk of NetBox API for my current project. Seeing this issue, I thought I'd dig deeper before adding more endpoints using the current code-generation approach.
NetBox is using django-rest-framework (drf) for the JSON api and django-rest-swagger (drs) for the API exploration API. drf bases it's schema support on coreapi, and drs glosses that in to the openapi/swagger standard format. But, coreapi doesn't have a capability of defining response bodies, so the resulting swagger lacks responses.
The drf documentation offers a couple of alternatives. I'm going to try these out locally and see if they result in a usable go-netbox client. If they do, I'll approach Jeremy about changing the API doc support in NetBox.
Would be great!
Tested go-swagger some time ago as well. I was able to generate a working tenant-list-client by adding definition and responses by hand in the generated swagger.json. In general this should work.
If someone is interrested:
Definition: https://gist.github.com/chrigl/3e35f98272637baf930d8d3c9b74d206#file-json-L23585 Response: https://gist.github.com/chrigl/3e35f98272637baf930d8d3c9b74d206#file-json-L20918
The first alternative I tried currently has some trouble with Netbox's pattern of labeled values backed with integer or boolean values. I'm going to link the issue here to keep track of what I tried.
Looked at https://github.com/limdauto/drf_openapi but having trouble getting it to work. It expects versioning, and URLPath versioning specifically. Netbox uses Accept header versioning instead. Also the idea that all the serializers should subclass VersionedSerializer would lead to many code changes in the netbox codebase.
With some custom FieldInspectors to deal with the custom ChoiceFieldSerializaer I was able to generate a full client. Will test-drive it next week. How do we distribute a fully generated client? Check it in to this repo? Should I open a PR?
since #28 we should close this. Amazing work @davcamer.
Hi,
this might be a stupid question but why is this an extra implementation and not generated from swagger.json via something like https://github.com/go-swagger/go-swagger?
Am I missing something obvious?
Kind regards SchwarzM