Openapi-generator: [SWIFT4] Request does not conform to protocol 'Decodable'

Created on 29 Aug 2018  路  10Comments  路  Source: OpenAPITools/openapi-generator

Description

Every request got the error "Type 'MyRequestRequest' does not conform to protocol 'Decodable'"

openapi-generator version

3.2.2

Command line used for generation

openapi-generator generate - swagger.json -g swift4 -o api

Using Xcode 10 and Newest Swift version

Swift Bug

Most helpful comment

I think this should be re-opened. My understanding is that Swagger spec allows free-form objects using type: object.

All 10 comments

Problem solved. The solution was that the API got some mistakes.
When an Request defines his params as object :
"properties": { "params": { "type": "object" },
the API generates code which is not Codeable.
public var params: Any

defining an object and referencing it in the request solved the problem

I think this should be re-opened. My understanding is that Swagger spec allows free-form objects using type: object.

Any pointers to how we should handle type: objects instances?

I haven't tried it yet but I was thinking maybe the generator could use Codable instead of Any?

Any updates on this? It looks like using Any anywhere on an object breaks building since it's not Codable.

Any updates on this? I have the same problem.

Instead of Any, what should be a proper type in Swift to map type: object?

Hi. This is the Kubernetes api document definition. Value can be int-or-string.

"v1.RollingUpdateDaemonSet": {
    "description": "Spec to control the desired behavior of daemon set rolling update.",
    "properties": {
    "maxUnavailable": {
        "description": "",
        "format": "int-or-string",
        "type": "object"
    }
    },
    "type": "object"
},

I'm aware of such definition in Kubernetes as I was involved in the client generation for the Kubernetes API before.

If I remember correctly, it's using OpenAPI v2 to describe the API. In the long term, better upgrade to OpenAPI v3 and use oneOf to describe such property, e.g.

oneOf:
  - type: string
  - type: integer

In Swift, what type would be the best to store something that can be either a string or integer?

So that's it, thank you very much for your answer. Kubernetes is written in the go language, and there is no mature implementation of openapi v3 in go, so upgrading from v2 to v3 would be a big project. But it does need to be addressed from the Kubernetes side.

What about mapping type: object as a String in Swift for the time being as everything can be represented as a string and developers and convert the string into whatever type that's appropriate and the auto-generated Swift will at least compile?

You can test this workaround/solution using the typeMapping option for the time being: https://openapi-generator.tech/docs/usage/#type-mappings-and-import-mappings

Was this page helpful?
0 / 5 - 0 ratings