swagger-api / swagger-api/swagger-codegen
[Swift3] Array of string appears broken
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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