yonaskolb / SwagGen

OpenAPI/Swagger 3.0 Parser and Swift code generator
MIT License
626 stars 147 forks source link

Integers contained in a [String: Any] dictionary are inferred to be booleans instead of integers #245

Open marcelvoss opened 4 years ago

marcelvoss commented 4 years ago

Hi there 👋,

first of all, thanks for building this generator. It is a pleasure to use.

While debugging, I stumbled upon a problem with the way freeform dictionary fields (such as[String: Any]) are being encoded. Where 0 and 1 can be valid integer fields, they are being encoded as booleans. Looking at the implementation of AnyCodable.swift, it seems like in these cases Bool is the first (and best match), although not entirely correct. I know it is possible to cast and type check booleans using CFBooleanRef within NSJSONSerialization and then encode/decode correctly. I'm not sure the same trick also applies to Codable-based serializations though.