swagger-api / swagger-api/swagger-codegen

Create a swift4 code generator and templates

Open
#6,002 5 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Swift Enhancement: New generator
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

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

  • The Codable protocol, which is actually two protocols (Decodable and Encodable)
  • Because of protocol extensions, for most cases, all the model classes have to do is simply declare their conformance to the Codable protocol.

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the proposed swift4 language and its Mustache templates, starting from the swift4 branch and the ./bin/swift4-petstore-all.sh generation command. Compare the generated Pet model with the Codable-based example in the issue, then verify that the generator produces the intended Swift 4 models and templates.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.