Generator does not handle empty strings in enum fields (Go)
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 333
- Avg merge
- 16h 29m
- Merged PRs (30d)
- 116
Description
We are trying to generate a Go client from the Clever API openapi specification available at the below link:
https://github.com/Clever/swagger-api/blob/master/v3.0.yml
This includes many enum definitions that follow this basic pattern.
```
gender:
enum:
- M
- F
- X
- ""
type: string
```
This is resulting in the following generated code
```
const (
M_STUDENT_GENDER Student_gender = iota
F_STUDENT_GENDER
X_STUDENT_GENDER
)
func (i Student_gender) String() string {
return []string{"M", "F", "X"}[i]
}
func ParseStudent_gender(v string) (any, error) {
result := M_STUDENT_GENDER
switch v {
case "M":
result = M_STUDENT_GENDER
case "F":
result = F_STUDENT_GENDER
case "X":
result = X_STUDENT_GENDER
default:
return 0, errors.New("Unknown Student_gender value: " + v)
}
return &result, nil
}
```
This results in the valid value of "" being interpreted as an error.
Contributor guide
Research direction
Reproduce generation with the linked Clever OpenAPI specification and inspect the generator entry point that renders Go enum constants and parsing code; the payload does not name a repository file or test. Done means an enum containing an empty string is represented in generated Go code and accepted by parsing without being reported as unknown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100