swagger-api / swagger-api/swagger-codegen

[Codegen][Swift] Generic specialization of Decoders.decode func doesn't work

Open
#1,667 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Decoders class have several specializations for decodable type:

  • T - (object or primitive type)
  • [T] - (array)
  • [Key:T] - (dictionary)

Here there are:

static func decode<T>(clazz clazz: [T].Type, source: AnyObject) -> [T] { ... }
static func decode<T, Key: Hashable>(clazz clazz: [Key:T].Type, source: AnyObject) -> [Key:T] { ... }
static func decode<T>(clazz clazz: T.Type, source: AnyObject) -> T { ...  }

Actually, only the last specialization is invoked, even on arrays (which type is printed in log as Array). Seems a problem with a type deduction in swift generics.

i'm using:

  • Xcode 7.0.1 (7A1001)
  • Swift 2.0

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

Start by reproducing the generated Swift client behavior with the Decoders.decode overloads shown in the issue, using the stated Swift 2.0 and Xcode 7.0.1 versions if available. Inspect why array and dictionary values select the generic T overload; done when the appropriate specialized overload is selected for each supported decoded type.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.