Skip to content

[Swift] Incorrect generation emun type for swift language #3934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
razalur opened this issue Oct 6, 2016 · 9 comments
Closed

[Swift] Incorrect generation emun type for swift language #3934

razalur opened this issue Oct 6, 2016 · 9 comments

Comments

@razalur
Copy link

razalur commented Oct 6, 2016

Description

Hello! I generate client for swift language. There is incorrect swift language syntax generated for enum type.

For example for this json code:

{
  "basePath": "/myPath",
  "definitions": {
    "SomeValue": {
      "properties": {
        "level": {
          "description": "word (1 = Simple1 , 2 = Simple2 , 3 = Simple3 , 4 = Simple4 )",
          "enum": [
            1,
            2,
            3,
            4
          ],
          "format": "int32",
          "type": "integer"
        }
      },
      "type": "object"
    }
  },
  "paths": {},
  "swagger": "2.0"
}

I've got this swift code for enum type "Level":

public enum Level: String { 
        case 1 = "1" 
        case 2 = "2"
        case 3 = "3"
        case 4 = "4"
    }

As you can see there are numbers after "case" keywords. But this is not correct syntax for swift (compiler error: "Expected identifier in enum 'case' declaration"). Unfortunately I can't change my json to avoid this. May be it is possible to change somehow the logic for swift code generation to get right solution?

Best regards,
Aleksey Razzhivaykin

@razalur razalur changed the title Incorrect generation emun type for swift language [Swift] Incorrect generation emun type for swift language Oct 6, 2016
@wing328 wing328 added this to the v2.2.2 milestone Oct 6, 2016
@wing328
Copy link
Contributor

wing328 commented Oct 6, 2016

@razalur thanks for reporting the issue. I'll take a look later today.

@wing328
Copy link
Contributor

wing328 commented Oct 6, 2016

@razalur I've filed #3941 so that enum with numeric value looks like this:

public enum Level: String { 
        case Number1 = "1" 
        case Number2 = "2"
        case Number3 = "3"
        case Number4 = "4"
    }

@wing328
Copy link
Contributor

wing328 commented Oct 7, 2016

@razalur PR merged into master. Please pull the latest master to give it a try.

@wing328 wing328 closed this as completed Oct 7, 2016
@razalur
Copy link
Author

razalur commented Oct 7, 2016

It seems that nothing changed... Please, check it again....
I've got again

public enum Level: String { 
        case 1 = "1" 
        case 2 = "2"
        case 3 = "3"
        case 4 = "4"
    }

instead of

public enum Level: String { 
        case Number1 = "1" 
        case Number2 = "2"
        case Number3 = "3"
        case Number4 = "4"
    }

@wing328
Copy link
Contributor

wing328 commented Oct 7, 2016

@razalur did you use editor.swagger.io to generate the Swift API client?

editor.swagger.io is using the latest stable version (not the latest master) so plesae build the JAR locally based on the latest master.

@razalur
Copy link
Author

razalur commented Oct 7, 2016

I use:

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i /Users/User/Desktop/test.json -l swift -o /tmp/

Is it right way?
and in git log I can see you commit. But nothing changed in the result.

@wing328
Copy link
Contributor

wing328 commented Oct 7, 2016

Did you do a mvn clean package?

@razalur
Copy link
Author

razalur commented Oct 7, 2016

No. Thank you! Now it's ok!

@c100k
Copy link

c100k commented Mar 14, 2017

Hello. Actually, the PR does not solve completely the problem. For example, for this type of definition :

resolution:
  type: string
    enum:
      - 640x360
      - 950x540
      - 1280x720
      - 1920x1080
      - 2592x1458

Executing with the latest version :

swagger-codegen generate -i http://example.com/swagger.json -l swift3 -o /tmp/swift/

Outputs :

public enum Resolution: String { 
    case 640x360 = "640x360"
    case 950x540 = "950x540"
    case 1280x720 = "1280x720"
    case 1920x1080 = "1920x1080"
    case 2592x1458 = "2592x1458"
}

which is not valid Swift3 code.

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

No branches or pull requests

3 participants