-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Go] Add Go API client generator #1747
Conversation
@casualjim want to look at this? |
This is super optimistic and will only work for very simple models. I'm very close to having something ready that makes all of it work properly. I have tickets on my backlog to submit integrations back to this project. @wing328 would you like to help make go-swagger/go-swagger better? There are 3 open issues left wrt to generating models. |
@casualjim I agree with you that the go generator in this PR is very basic and won't work with I'm definitely aware of all the great work you've done with go-swagger and I've been referring people to your project when they're looking for a go api server/client generator based on swagger spec. If I understand correctly, go-swagger client constructs the operations/methods dynamically based on a swagger spec during runtime, which means there's no static API files created for operations (similar to swagger-js, and now there's also a static API client for JS). My intention was to create a static API client for Go and I'm still referring people to go-swagger for a more mature API client. Can you share with us the URL to the remaining 3 open issues for go-swagger client so that anyone from the swagger community who is interested can potentially help on those? |
There is no real dynamic aspect to the client that gets generated by go-swagger. There is a bit of content type inference that happens but other than that everything else is static. I have these 2 issues open: The plan with those is to use a process builder and look in the path for the go swagger binary and map the required command line args. Perhaps that's an alternative implementation for this pull request? it will already support more features than this code. You can see here how none of it is dynamic: https://github.com/go-swagger/go-swagger/blob/master/examples/todo-list/client/todos/find_parameters.go Remaining issues: https://github.com/go-swagger/go-swagger/milestones/Minimal%20first%20release |
After I ran the command below, I got only Go model files under
I checked the files but didn't find I looked at the example in http://goswagger.io/generate/client/ and found the following example code:
which seems to me it's loading the spec from a URL/file and construct the "transport" dynamically but as you've pointed out you're not really doing anything dynamic in the Go API client so my understanding is wrong. |
That petstore spec doesn't validate:
Go swagger also runs into a nil issue.
but it does generate more stuff:
|
Here is the full output of the command I ran:
Does it mean I need to specify the |
I think it wants you to do this in a subdir of $GOPATH
|
Got the same result within a subfolder
|
In this path: $GOPATH/src/random_dir The src is important. the location for go sources in the GOPATH is $GOPATH/src |
OK. Running the command inside a subfolder under If I might, I would suggest updating the error message |
I've also fixed the issues that came from generating a client for an invalid spec, so if you do |
Thanks for the quick turnaround. Confirmed that I no longer see the nil pointer exception after running |
@casualjim given that the Go API client generated by go-swagger is a lot more mature, do you mind if we update our Go API client to mimic yours? We'll put down the following in each auto-generated files in the Go API client
|
If you want I can generate a release. Perhaps this could be embedded in swagger codegen, and it can shell out with process builder? Which will allow us to close this ticket? go-swagger/go-swagger#109 |
@casualjim I've discussed with @fehguy and decided to merge this PR into master so that the community can help contribute to make it better. |
[Go] Add Go API client generator
the code this generates is invalid afaict |
@casualjim we've a very simple test script: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/go/test.go |
why aren't you just shelling out to go-swagger.
because for all these things you'd require a custom deserializer/serializer. So please I urge you guys to just integrate by shelling out to the go-swagger client. There are number of challenges that are unique to go which is why I didn't do it in this project. So instead of merging a janky client and starting all that work again, why not reuse mine? That first import ./swagger is super invalid because it breaks everything that wants to depend on it. |
We have to run non interactive and only in the jvm unfortunately |
hi, I am new to this tool. I am not able to generate the enum type with the present code. Does it support the enum generation within the GoClientCodegen.java and same within the mustache file? Please guide me what to do.. |
This PR contains a functional Golang API client, which has been tested with Petstore (GET, POST form, POST JSON).
There are still some features pending to be added, e.g. authentication, default header, file upload, unit tests and more. I'll create some tasks for tracking shortly.