Skip to content
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

[Swift3] Wrong enum types generated when enum is of custom type #5452

Closed
davidpasztor opened this issue Apr 21, 2017 · 2 comments
Closed

[Swift3] Wrong enum types generated when enum is of custom type #5452

davidpasztor opened this issue Apr 21, 2017 · 2 comments

Comments

@davidpasztor
Copy link
Contributor

davidpasztor commented Apr 21, 2017

Description

Swift enum types are incorrect using swagger-codegen when the type should be a custom class
codegen generates an enum of Strings instead of an enum of custom types
Code generated by codegen:

public enum SomeType: String { 
        case foo = "Foo"
        case bar = "Bar"
        case bee = "Bar"
    }

I have manually managed to fix the enum and this is the correct Swift enum with custom types, where Foo, Bar and Bee are all custom classes that inherit from the same class in which SomeType is declared.

public enum SomeType {
        case foo(Foo)
        case bar(Bar)
        case bee(Bee)
    }

The Java version of swagger-codegen has been fixed already and generates the following, correct code:

public enum SomeTypeEnum {
    @SerializedName("Foo")
    FOO("Foo"),
    
    @SerializedName("Bar")
    BAR("Bar"),
    
    @SerializedName("Bee")
    BEE("Bee");

    private String value;

    SomeTypeEnum(String value) {
      this.value = value;
    }

    @Override
    public String toString() {
      return String.valueOf(value);
    }
  }
Swagger-codegen version

2.2.2

Swagger declaration file content or url
Something:
    type: object
    description: "Something description"
    allOf:
      - $ref: '#/definitions/_Item'
      - type: object
        discriminator: customType
        required:
          - customType
          - category
        properties:
          propertyA:
            type: array
            description: Some description
            items:
              type: string
              pattern: '[a-zA-Z0-9-]{1,20}'
          propertyB:
            type: array
            description: Another description
            items:
              type: string
              pattern: '[a-zA-Z0-9-]{1,20}'
          propertyC:
            description: propertC
            enum:
              - first
              - second
              - other
            type: string
            default: first
          propertyD:
            description: something else
            type: string
            pattern: '[a-zA-Z -]{1,70}'
          customType:
            type: string
            description: customType description
            enum:
              - Foo
              - Bar
              - Bee
Command line used for generation

swagger-codegen generate -i /path/spec.yaml -l swift3

Steps to reproduce

Generate swift3 code using codegen from command line with the above specification file

Related issues

#4484

Suggest a Fix
@yonaskolb
Copy link
Contributor

Not sure I understand. In that spec snippet there are only enums with type string. Could you post part of a spec and then what you would expect to be generated?

@wing328
Copy link
Contributor

wing328 commented May 21, 2017

@davidpasztor closing this as there's no reply to the question by @yonaskolb

@wing328 wing328 closed this as completed May 21, 2017
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