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

Swift 3 Code Generation Wrong Enums #4484

Closed
Vario opened this issue Jan 3, 2017 · 2 comments
Closed

Swift 3 Code Generation Wrong Enums #4484

Vario opened this issue Jan 3, 2017 · 2 comments

Comments

@Vario
Copy link

Vario commented Jan 3, 2017

Description

Hello, i try to generate my Server API in Swift 3 with swagger-codegen.
But my enums are created wrong.
The output of a class with an enum property looks like this

`
open class DTO: JSONEncodable {

public enum Status: String { 
    case RAWSTARTED_ENUMSTARTED = "'{raw=STARTED, enum=Started}'"
    case RAWPAUSED_ENUMPAUSED = "'{raw=PAUSED, enum=Paused}'"
    case RAWFINISHED_ENUMFINISHED = "'{raw=FINISHED, enum=Finished}'"
}
public var startedAt: Int64?
public var status: Status?
public init() {}
open func encodeToJSON() -> Any {
    var nillableDictionary = [String:Any?]()
    nillableDictionary["startedAt"] = self.startedAt?.encodeToJSON()
    nillableDictionary["status"] = self.status?.rawValue
    let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
    return dictionary
}

}`

I use the Status type in more than one class and its generated within each DTO file additionally.

Swagger-codegen version 2.2.1

i use the version 2.2.1 which i exported from this project

Swagger declaration file content or url

this is the line i use to generate my code
#2. swagger code generieren
echo —————GENERATE CODE FILES----------------
java -jar swagger-codegen-cli-2.2.1.jar generate -i ./swagger-definition.json -l swift -o newAPI -t swift3_template

the swift3_template folder is from this projects directory too /modules/swagger-codegen/src/main/resources/swift3

within the samples/client/petstore/swift3 folder there are models with enum types which are generated correctly.

i tried using -l swift3 but this is not available although in the /bin/swift3-petstore.sh there is the following content
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" ags="$@ generate -t modules/swagger-codegen/src/main/resources/swift3 -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l swift3 -c ./bin/swift3-petstore.json -o samples/client/petstore/swift3/default"

here is a language of -l swift3 defined?

what am i doing wrong?

@wing328
Copy link
Contributor

wing328 commented Jan 4, 2017

i tried using -l swift3 but this is not available although in the /bin/swift3-petstore.sh there is the following content

Have you run mvn clean package to rebuild the JAR locally based on the latest master?

@Vario
Copy link
Author

Vario commented Jan 4, 2017

i fixed this problem by using a jar file from this source
https://oss.sonatype.org/content/repositories/snapshots/io/swagger/swagger-codegen-cli/2.2.2-SNAPSHOT/
there the swift3 parameter is available and the classes are generated correctly

there is only one thing left now. enums used in classes are generated within a class. if 2 classes use a basically identical enum this enum is added in each class where its used.

you can see that in the DTO class above. if a DTO2 class would use this enum aswell it would be generated in it too. is there a solution?

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

2 participants