templates.kotlin.nested_class_map.mustache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-kotlin-schema-codegen Show documentation
Show all versions of json-kotlin-schema-codegen Show documentation
Code generation from JSON Schema to Kotlin or Java
{{#isObject}}{{&indent}}class {{&className}}(
{{&indent}} private val cg_map: Mapclass_map_type}}>
{{&indent}}) : Mapclass_map_type}}> by cg_map {
{{#additionalPropertiesNeedsInit}}
{{&indent}} init {
{{#properties}}{{#defaultValue}}{{&indent}} if (cg_map.containsKey("{{&name}}")){{#validations}}{{#first}} {{&openBrace}}{{/first}}{{/validations}}
{{#indent.increment}}{{>class_map_property}}{{/indent.increment}}{{#validations}}{{#first}}{{&indent}} }
{{/first}}{{/validations}}{{/defaultValue}}{{^defaultValue}}{{!
}}{{#nullable}}{{&indent}} if (cg_map.containsKey("{{&name}}")){{!
}}{{#isArray}} {{&openBrace}}{{/isArray}}{{^isArray}}{{#validations}}{{#first}} {{&openBrace}}{{/first}}{{/validations}}{{/isArray}}
{{#indent.increment}}{{>class_map_property}}{{/indent.increment}}{{!
}}{{#isArray}}{{&indent}} }
{{/isArray}}{{^isArray}}{{#validations}}{{#first}}{{&indent}} }
{{/first}}{{/validations}}{{/isArray}}{{/nullable}}{{^nullable}}{{&indent}} require(cg_map.containsKey("{{&name}}")) { "required property missing - {{&name}}" }
{{>class_map_property}}{{/nullable}}{{/defaultValue}}{{/properties}}{{!
}}{{^properties}}{{#additionalProperties}}{{#validations}}{{#first}}{{&indent}} cg_map.entries.forEach { (key, value) ->
{{/first}}{{#indent.increment}}{{#mapEntryContext}}{{>validations_2}}{{/mapEntryContext}}{{/indent.increment}}{{#last}}{{&indent}} }
{{/last}}{{/validations}}{{/additionalProperties}}{{/properties}}{{#validations}}{{>validations_2}}{{/validations}}{{&indent}} }{{/additionalPropertiesNeedsInit}}
{{#properties}}
{{#schema}}{{#description}}{{&indent}} /** {{&safeDescription}} */
{{/description}}{{/schema}}{{&indent}} val {{&kotlinName}}: {{>type}}{{#defaultValue}}
{{#isArray}}{{&indent}} @Suppress("unchecked_cast")
{{/isArray}}{{&indent}} get() = if (cg_map.containsKey("{{&name}}")) cg_map["{{&name}}"] as {{>type}} else {{>default_value}}
{{/defaultValue}}{{^defaultValue}}{{#nullable}}
{{#isArray}}{{&indent}} @Suppress("unchecked_cast")
{{/isArray}}{{&indent}} get() = cg_map["{{&name}}"] as {{>type}}
{{/nullable}}{{^nullable}} by cg_map
{{/nullable}}{{/defaultValue}}{{/properties}}
{{&indent}} override fun toString(): String = "{{&className}}(${cg_map.entries.joinToString { "${it.key}=${it.value}" }})"
{{&indent}} override fun equals(other: Any?): Boolean = this === other || other is {{&className}} && cg_map == other.cg_map
{{&indent}} override fun hashCode(): Int = cg_map.hashCode()
{{/isObject}}{{#isString}}{{&indent}}enum class {{&className}} {
{{#enumValues}}{{&indent}} {{&.}}{{^last}},
{{/last}}{{/enumValues}}{{/isString}}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy