Skip to content

[BUG] [Swift5] special characters in enum values lead to Xcode compile error #11107

@mbruegmann

Description

@mbruegmann

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

EnumValues with special characters will produce enum var names with special characters which causes compile errors in Xcode.
In our example we have the following property:

 "aspectRatio" : {
          "type" : "string",
          "enum" : [ "1:1", "4:5", "4:3", "9:16", "16:9" ]
        }

... generating this code:

 public enum AspectRatio: String, Codable, CaseIterable {
        case _1:1 = "1:1"
        case _4:5 = "4:5"
        case _4:3 = "4:3"
        case _9:16 = "9:16"
        case _16:9 = "16:9"
    }
openapi-generator version

5.3.1

Generation Details

swift5

Suggest a fix

Add .replaceAll("\\W+", "_") in public String toEnumVarName(String name, String datatype) in class Swift5ClientCodegen.
This is also done in the DefaultCodegen class and in some of the other generator classes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions