swagger-api / swagger-api/swagger-codegen

[Swift3] Array of string appears broken

Open
#6,238 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

Hi guys,
Arrays of strings appear broken in the swift 3 client. Using the swagger declaration below, it generates the following file:

public typealias UserInstruments = []

When it should be

public typealias UserInstruments = [String]

And in the Decoders:

        // Decoder for UserInstruments
        Decoders.addDecoder(clazz: UserInstruments.self) { (source: AnyObject, instance: AnyObject?) -> UserInstruments in
            let sourceArray = source as! [AnyObject]
            return sourceArray.map({ Decoders.decode(clazz: .self, source: $0, instance: nil) })
        }

When it should be:

        // Decoder for UserInstruments
        Decoders.addDecoder(clazz: UserInstruments.self) { (source: AnyObject, instance: AnyObject?) -> UserInstruments in
            let sourceArray = source as! [AnyObject]
            return sourceArray.map({ Decoders.decode(clazz: String.self, source: $0, instance: nil) })
        }

Still trying to spot the problem, but if someone that actually coded the client could have a look I would greatly appreciate it!

Thanks!

Swagger-codegen version

2.2.3

Swagger declaration file content or url
  UserInstruments:
    type: array
    description: |
      An array of the instrument identifiers that the user plays.
    items:
      type: string
      pattern: ^[a-z]+\.[a-z-]+$
    example:
    - keyboards.grand-piano
    - brass.trumpet
    - strings.violin
Command line used for generation

swagger-codegen generate -i https://url.com -l swift3 -o ../api-client-swift3 -c conf.json

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

Reproduce the issue with the shown Swagger declaration and the swift3 generation command. Inspect the Swift3 generator templates responsible for the array typealias and decoder, and consider the issue done when string arrays generate [String] and decode with String.self.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.