microsoft/kiota
Vedi su GitHubGenerator does not handle empty strings in enum fields (Go)
Open
#4329 aperta il 13 mar 2024
generatorhelp wantedtype:bug
Metriche repository
- Star
- (3783 star)
- Metriche merge PR
- (Metriche PR in attesa)
Descrizione
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.