swagger-api / swagger-api/swagger-codegen-generators
Can we have a discussion about the Go code generator?
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
So I saw that 3.0.0 will use this repository for codegen generators. Version 2.3.x introduced some major breaking changes to the produced code. While most of these changes made sense, some of them are - in my opinion - bad choices.
I would like to use the chance that releasing 3.0.0 is, to start a discussion on providing a better code generator for Golang.
I'd like to start with some things that I think are really well done in the new 2.3.x release:
- It's now possible to provide a custom
http.Client - It's now possible provide a
context.Contextin API calls
I think there are also some issues.
- Redirects do apparently no longer work, because all status codes higher than 299 result in an error:
if localVarHttpResponse.StatusCode >= 300 {
bodyBytes, _ := ioutil.ReadAll(localVarHttpResponse.Body)
return localVarHttpResponse, reportError("Status: %v, Body: %s", localVarHttpResponse.Status, bodyBytes)
}
- Adding request bodies now requires passing a
map[string]interface{}that needs, for example, abodykey.
The second limitation is especially painful from an API point of view as type assertions are necessary to decode the payload, and the API is not very developer friendly in the context of Go. In real-world use it looks something like this:
CreateResource(context.Context, map[string]interface{}{"body": &SomeStruct{}})
I propse that instead, a type is used to solve this, for example:
type CreateResourceParameters struct {
Body *SomeStruct
Path ...
Query ...
}
This would make the process of passing down request parameters much more usable and less error prone.
Let me know what you think.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the Go generator behavior described in the issue, especially status-code handling and map[string]interface{} request bodies. The first step is to gather maintainer direction on whether typed parameter structs and changed redirect handling are desired for 3.0.0. Done would require an agreed design, implementation scope, and validation criteria.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 15/100