json-kotlin-schema-codegen
json-kotlin-schema-codegen copied to clipboard
[0.81] CustomClasses doesn't support generic types
With the following property definition:
"repositories": {
"description": "The list of repositories being sourced.",
"type": "object",
"format": "map",
"additionalProperties": {
"$ref": "https://aetheric.co.nz/schema/gsm/repository"
}
}
and the following config:
"customClasses": {
"format": {
"map": "kotlin.collections.Map"
}
}
I end up with:
import kotlin.collections.Map
data class Settings(
val repositories: Map? = null
)
which is invalid.
If I add the generic signature to the type, it includes it in the import, which is also invalid.
I worked around the issue by creating a typealias and mapping to that, but I can see two ways to improve the experience:
- Strip off generic typing on the import declaration.
- Make
objecttypes without an explicitnameor$iddefault toMap<String,?>where?is the common property type.
Hi – very sorry not to have responded sooner. Both your suggestions are good ones, but in the meantime, have you tried:
typealias MapStringAny = Map<String, Any>
Then, use MapStringAny in the customClasses configuration.
Indeed, that's how I worked around it, so I really just wanted to document that.