swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.05k stars 6.03k forks source link

Create a swift4 code generator and templates #6002

Open ehyche opened 7 years ago

ehyche commented 7 years ago
Description

Swift 4 (announced at WWDC 2017 in June 2017) introduces some features which make serialization and deserialization in Swift much simpler:

I have written an Xcode playground which explores lots of details about the Codable protocol here:

https://github.com/ehyche/xcode-playgrounds

in the LearningAboutCodable.playground file.

So I have created a "swift4" language for swagger-codegen which greatly simplifies the mustache templates, and thus the generated models. Now, most models simply have the properties and that's it. For example, here is the Pet class:

open class Pet: Codable {

    public enum Status: String, Codable { 
        case available = "available"
        case pending = "pending"
        case sold = "sold"
    }
    public var id: Int64?
    public var category: Category?
    public var name: String?
    public var photoUrls: [String]?
    public var tags: [Tag]?
    /** pet status in the store */
    public var status: Status?

    public init() {}

}
Swagger-codegen version

I am proposing adding this to master. I have created the swift4 language on a branch, and will be creating a PR for it.

Command line used for generation
./bin/swift4-petstore-all.sh
Steps to reproduce

New language.

ehyche commented 7 years ago

I have this new "swift4" language ready to go on a branch off of master. But I guess I need to get the proper permissions before I can push this branch up.

ehyche commented 7 years ago

Note that you need an Xcode 9 beta in order to use the LearningAboutCodable.playground and the swift4 language.

wing328 commented 7 years ago

@ehyche thanks for offering help to add the Swift4 generator πŸ‘ πŸ‘ πŸ‘

Let us know if you need help with the PR.

cc @jaz-ah @Edubits @jaz-ah

ehyche commented 7 years ago

@wing328 : Can you give me write access to the repo so that I can push my branch up?

ehyche commented 7 years ago

@wing328 : ah, I just re-read the instructions for contributing. I need to first fork the repo.