json-kotlin-schema-codegen icon indicating copy to clipboard operation
json-kotlin-schema-codegen copied to clipboard

[0.81] CustomClasses doesn't support generic types

Open Tzrlk opened this issue 3 years ago • 2 comments

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 object types without an explicit name or $id default to Map<String,?> where ? is the common property type.

Tzrlk avatar Sep 30 '22 21:09 Tzrlk

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.

pwall567 avatar Oct 09 '22 11:10 pwall567

Indeed, that's how I worked around it, so I really just wanted to document that.

Tzrlk avatar Oct 14 '22 05:10 Tzrlk