Skip to content

Support for Golang #325

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

Closed
flavianh opened this issue Nov 10, 2014 · 21 comments
Closed

Support for Golang #325

flavianh opened this issue Nov 10, 2014 · 21 comments

Comments

@flavianh
Copy link

Is it in the backlog?

@webron
Copy link
Contributor

webron commented Nov 10, 2014

Obviously, we can't reliably provide implementations for all existing languages since we're not proficient with everything out there. However, such contributions would be gladly accepted!

@flavianh
Copy link
Author

Great! Do you have guidelines for such implementations? How hard is it to make one? I've checked the Python generation files, it seems like there is not so much code

@webron
Copy link
Contributor

webron commented Nov 10, 2014

There's no code at all really, it's just mustache templates.

I think the easiest way would be to look at the current implementations - https://github.com/swagger-api/swagger-codegen/tree/master/src/main/resources

Keep in mind that most work that's done now is towards the next major version of the codegen, so it may be better to contribute to that branch - https://github.com/swagger-api/swagger-codegen/tree/develop_2.0/src/main/resources

@flavianh
Copy link
Author

OK thanks

@webron
Copy link
Contributor

webron commented Nov 10, 2014

No, thank you! It would be great to add support for additional languages. Feel free to ask any specific questions as you encounter them.

@fehguy
Copy link
Contributor

fehguy commented Nov 10, 2014

I believe @casualjim has worked on this some already

@c4milo
Copy link

c4milo commented Dec 19, 2014

I might be willing to contribute support for Go, despite my distaste for Scala :P

@fehguy
Copy link
Contributor

fehguy commented Dec 19, 2014

well, if you're working with the develop_2.0 branch, the codegen code is pure java. So you don't need to plug your nose :)

@mattolenik
Copy link

Is any of this work yet available (even if untested)? I'm on a project where this would be useful, and I'm contemplating writing Golang support for Swagger.

@fehguy
Copy link
Contributor

fehguy commented Mar 10, 2015

I suggest joining forces with @casualjim who is very far along with his project.

@mattolenik
Copy link

I'd rather just implement a generator for the existing codegen, rather than write something from the ground up in Go.

Unfortunately, I've run into a problem. I'm not sure if I the codegen model supports being able to generate idiomatic Go code. What I want is to have a Go package for each version of each API, and in that package will be the code for the models and the operations. I don't want separate modules for operations and models. Models and operations need to go into the same directory, and that directory needs to be based on the operation name. For example, if I have some operation "foo" then you'd expect to see all the code under "src/my/api/foo/v1", and you'd expect each .go source file in this directory to say "package foo" at the top.

Does this make sense? Is there any way I can do this with the current codegen model? This is a good example of the structure I'm trying to mimmic: https://github.com/google/google-api-go-client

@fehguy
Copy link
Contributor

fehguy commented Mar 12, 2015

Fork swagger-codegen, send me the URL and I'll send a pull request to help with the structure.

@casualjim
Copy link
Contributor

There are a bunch of reasons why I didn't do it in this codegen package. And mostly it's very challenging for me to get full support for the swager spec in the java version of swagger codegen.
I started out trying to customize this codegen instead and only after a bunch of fruitless attempts I went on with creating the entire generator stuff in go-swagger.
Go types are not as clear cut as it seems, when doing codegen. Then making default values is again not entirely straight forward in java. Struct literals etc all that stuff you kind of get for free when you use go.

At first i tried to keep it so I could at least reuse mustache templates but none of the go mustache packages I could find allows for self-referencing partial mustache templates. And it's something I needed because there are many validations etc that need to be respected. Again I tried many other ways to make mustache work, before moving on to the go template system.

Now if you can make it work all the better but those are the reasons I didn't/couldn't.
I also want to provide a reverse codegen that generates a swagger spec based on your go files.

And then I thought it made sense to have one command that helps you in dealing with all kinds of things swagger.

@mattolenik
Copy link

@casualjim, does your project currently do client generation? That's what I need at the moment.

@fehguy, thanks, but this is part of a project at work, so that's not really an option.

@casualjim
Copy link
Contributor

not at present. I have a couple of things left to fix with the server. if nobody else contributes to it then I should be able get to it in a week or so.

@alfonsodev
Copy link

I could help with the golang client, I forked and created a branch called golang_client_support branching from develop_2.0 https://github.com/alfonsodev/swagger-codegen/tree/golang_client_support
@fehguy can you send me a pull request with the structure?
If I have to only work with templates I'm pretty sure I can do it.
thanks!

@wing328
Copy link
Contributor

wing328 commented Jun 25, 2015

@alfonsodev thanks for offering help for the Golang client.

To start with, I would suggest you look at the work done by @casualjim as a reference. His latest PR (not merged) for another project (swagger-go) should be a good starting point - go-swagger/go-swagger#6.

Let me know if you need any help or have any questions..

@casualjim
Copy link
Contributor

The client generation has been merged to master now.

@wing328
Copy link
Contributor

wing328 commented Sep 14, 2015

👍 Thanks @casualjim

@wing328
Copy link
Contributor

wing328 commented Dec 21, 2015

FYI. I submitted #1747 to add a Go API client generator.

@wing328 wing328 modified the milestones: v2.1.5, v2.1.0 Dec 21, 2015
@wing328
Copy link
Contributor

wing328 commented Jan 22, 2016

#1747 (A beta Go API client) has been merged into master. Please take a look and let us know if you've any feedback.

The Go API client is not perfect and if you would like to contribute to make it better, please refer to the following list of tasks that are pending community contribution.

https://github.com/swagger-api/swagger-codegen/issues?q=is%3Aopen+is%3Aissue+label%3A%22Client%3A+Go%22

@wing328 wing328 closed this as completed Jan 22, 2016
@wing328 wing328 modified the milestones: v2.1.6, Future Mar 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants