icerockdev / moko-network

Network components with codegeneration of rest api for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev
Apache License 2.0
151 stars 29 forks source link

Map response type generated as primitive #104

Closed dalewking closed 3 years ago

dalewking commented 3 years ago

We have a call that returns a result type of:

        "schema" : {
          "type" : "object",
          "additionalProperties" : {
            "type" : "boolean"
          }
        }

which is essentially a Json object with values of Boolean. The API call is generated with a correct return type of kotlin.collections.Map<kotlin.String, kotlin.Boolean>, but the internal deserialization does not work. Here is what it generates:

    try {
        //primitive type
        return _httpClient.request(builder)
    } catch (pipeline: ReceivePipelineException) {
        throw pipeline.cause
    }

So it is treating the Map as a primitive type and not doing any special deserialization. When ran you get an error

E/HttpClient: Failure(io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel -> class kotlin.collections.Map

Note that this is with version 0.10.0 as we have been unable to upgrade to the latest as it requires upgrading to Kotlin 1.4.31 and that is causing us problems.

I notice that you have recently added code to handle map deserialization here but I don't think that would help here as the template is going to the case where it thinks the return type is primitive.

dalewking commented 3 years ago

Was able to workaround it by hacking to remove the additional properties block which converts the return type to JsonObject

Alex009 commented 3 years ago

we will add test for it later and fix if it will be reproduced

Alex009 commented 3 years ago

will be in 0.14.1