swagger-api / swagger-api/swagger-codegen
[Swift] Very large numbers are not converted to string correctly
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When working with very large numbers (in this case, timestamps in nanoseconds), the default printing by swift results in an exponent character in the string. For example:
let largeNumber: Double = 1.52639622817888e+16
print("\(largeNumber)") // results in "1.52639622817888e+16"
Swagger-codegen version
2.3.1
Steps to reproduce
This is reproducible in an Swift project that uses Doubles for request parameters, as long as the input Double is sufficiently large.
Related issues/PRs
TBD
Suggest a fix/enhancement
Proposed fix is to switch to using NumberFormatter()
let formatter = NumberFormatter()
let num = NSNumber(value: bigNumber)
print(formatter.string(from: num)) // results in "15263962281788800"
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
No source file or test is named. Reproduce the issue in a Swift project using a sufficiently large Double as a request parameter, then locate the generated Swift parameter serialization path and compare its output with the proposed NumberFormatter behavior. Done means large numeric values are serialized without exponent notation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100