Skip to content

Generator does not handle empty strings in enum fields (Go) #4329

Open

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    generatorIssues or improvements relater to generation capabilities.help wantedIssue caused by core project dependency modules or librarytype:bugA broken experience

    Type

    No type

    Projects

    • Status

      Todo 📃

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions