Invalid code generation for Kotlin when using not required but not nullable fields

Hi!

I tried to generate models for an entity using snowtype that has a few fields that are are not nullable, but also not required meaning we can’t send null but we can omit the whole field. The generated code makes these properties nonnullable and provides no mechanism to omit them, forcing us to provide a value. This seems to be a problem specifically for generated Kotlin code, as the Swift variant constructed nullable fields and omits them when generating the payload map.

Example schema

Generated code snippet

data class VideoID(
        var videoID: String,
        var videoName: String,

The easy solution would be to make these nullable in the model, and omit null values from the payload. That however would make it impossible to send null for a required but nullable field, given that kotlin has no natural way to express undefined as javascript do.

Hi! Thank you for these Snowtype bug reports and suggested improvements, they’re very helpful.

This specific problem has been fixed in Snowtype v0.8.4, released today.

Thanks for the quick fix! Works great :star:

3 Likes