yonaskolb / SwagGen

OpenAPI/Swagger 3.0 Parser and Swift code generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type 'ModelWithAdditionalProperties' does not conform to protocol 'Equatable'

Cy-4AH opened this issue · comments

Petstore spec generates

Type 'ModelWithAdditionalProperties' does not conform to protocol 'Equatable'

if generated with options modelType:struct modelInheritance:false

Happy to accept an easy PR for this

I just hit what I think is a related issue, where an OpenAPI spec that includes a bare object field generates a model with [String: Any]? that isn't Equatable.

In our codebase we have an enum that looks like this:

enum JSONAny: Codable, Equatable {
    case bool(_ value: Bool)
    case int(_ value: Int)
    case float(_ value: Double)
    case string(_ value: String)
    case array(_ value: [JSONAny])
    case dict(_ value: [String: JSONAny])
    case null

Generating with --option anyType:JSONAny would fix it (and maybe ModelWithAdditionalProperties too) if I could get JSONAny in scope. Some possible ways of doing that:

  1. Make my own template and add JSONAny.swift (but I'd prefer to stick to the standard one!)
  2. Add JSONAny.swift to the standard template (happy to contribute this if there's interest)
  3. Have the generator include an extra file -- could this be added? e.g. --option addFile:JSONAny.swift?
  4. Have the generator add an import statement -- could this be added? e.g. --option addImport:JSONAny?

@yonaskolb let me know if you like any of those options, and I can put together a PR.

@Cy-4AH --option anyType:Data may be another workaround

ezoic increase your site revenue