[kotlin][client] Add inheritance to Kotlin Client templates (#4453)

* Add inheritance to Kotlin Client templates

* Correct white spacing issues

* Rebuild kotlin client samples
This commit is contained in:
Matt Traynham 2020-02-01 22:12:11 -05:00 committed by GitHub
parent a496c2011f
commit 26c9c64634
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
72 changed files with 128 additions and 231 deletions

View File

@ -335,6 +335,10 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
CodegenModel cm = (CodegenModel) mo.get("model");
if (cm.getDiscriminator() != null) {
cm.vendorExtensions.put("x-has-data-class-body", true);
break;
}
for (CodegenProperty var : cm.vars) {
if (var.isEnum || isSerializableModel()) {

View File

@ -31,21 +31,22 @@ import java.io.Serializable
@Parcelize
{{/parcelizeModels}}
{{#multiplatform}}@Serializable{{/multiplatform}}{{#moshi}}{{#moshiCodeGen}}@JsonClass(generateAdapter = true){{/moshiCodeGen}}{{/moshi}}
{{#nonPublicApi}}internal {{/nonPublicApi}}data class {{classname}} (
{{#vars}}
{{#required}}{{>data_class_req_var}}{{/required}}{{^required}}{{>data_class_opt_var}}{{/required}}{{^-last}},{{/-last}}
{{/vars}}
) {{^serializableModel}}{{#parcelizeModels}} : Parcelable{{/parcelizeModels}}{{/serializableModel}}
{{^parcelizeModels}}{{#serializableModel}}: Serializable {{/serializableModel}}{{/parcelizeModels}}
{{#parcelizeModels}}{{#serializableModel}} : Parcelable, Serializable {{/serializableModel}}{{/parcelizeModels}}
{{#vendorExtensions.x-has-data-class-body}}
{
{{#nonPublicApi}}internal {{/nonPublicApi}}{{#discriminator}}interface{{/discriminator}}{{^discriminator}}data class{{/discriminator}} {{classname}}{{^discriminator}} (
{{#requiredVars}}
{{>data_class_req_var}}{{^-last}},
{{/-last}}{{/requiredVars}}{{#hasRequired}}{{#hasOptional}},
{{/hasOptional}}{{/hasRequired}}{{#optionalVars}}{{>data_class_opt_var}}{{^-last}},
{{/-last}}{{/optionalVars}}
){{/discriminator}}{{#parent}}{{^serializableModel}}{{^parcelizeModels}} : {{parent}}{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{#serializableModel}}{{^parcelizeModels}} : {{parent}}, Serializable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{^serializableModel}}{{#parcelizeModels}} : {{parent}}, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{#serializableModel}}{{#parcelizeModels}} : {{parent}}, Serializable, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{#serializableModel}}{{^parcelizeModels}} : Serializable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{^serializableModel}}{{#parcelizeModels}} : Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{#serializableModel}}{{#parcelizeModels}} : Serializable, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#vendorExtensions.x-has-data-class-body}} {
{{/vendorExtensions.x-has-data-class-body}}
{{#serializableModel}}
{{#nonPublicApi}}internal {{/nonPublicApi}}companion object {
private const val serialVersionUID: Long = 123
}
{{/serializableModel}}
{{#discriminator}}{{#requiredVars}}
{{>interface_req_var}}{{/requiredVars}}{{#optionalVars}}
{{>interface_opt_var}}{{/optionalVars}}{{/discriminator}}
{{#hasEnums}}
{{#vars}}
{{#isEnum}}

View File

@ -9,4 +9,4 @@
@SerializedName("{{{vendorExtensions.x-base-name-literal}}}")
{{/gson}}
{{/multiplatform}}
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") {{/multiplatform}}{{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isListContainer}}{{#isList}}kotlin.collections.List{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{classname}}.{{{nameInCamelCase}}}>{{/isListContainer}}{{^isListContainer}}{{classname}}.{{{nameInCamelCase}}}{{/isListContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") {{/multiplatform}}{{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isListContainer}}{{#isList}}kotlin.collections.List{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{classname}}.{{{nameInCamelCase}}}>{{/isListContainer}}{{^isListContainer}}{{classname}}.{{{nameInCamelCase}}}{{/isListContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}

View File

@ -9,4 +9,4 @@
@SerializedName("{{{vendorExtensions.x-base-name-literal}}}")
{{/gson}}
{{/multiplatform}}
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") @Required {{/multiplatform}}{{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isListContainer}}{{#isList}}kotlin.collections.List{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{classname}}.{{{nameInCamelCase}}}>{{/isListContainer}}{{^isListContainer}}{{classname}}.{{{nameInCamelCase}}}{{/isListContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}?{{/isNullable}}
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") @Required {{/multiplatform}}{{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isListContainer}}{{#isList}}kotlin.collections.List{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{classname}}.{{{nameInCamelCase}}}>{{/isListContainer}}{{^isListContainer}}{{classname}}.{{{nameInCamelCase}}}{{/isListContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}?{{/isNullable}}

View File

@ -0,0 +1,12 @@
{{#description}}
/* {{{description}}} */
{{/description}}
{{^multiplatform}}
{{#moshi}}
@Json(name = "{{{vendorExtensions.x-base-name-literal}}}")
{{/moshi}}
{{#gson}}
@SerializedName("{{{vendorExtensions.x-base-name-literal}}}")
{{/gson}}
{{/multiplatform}}
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") {{/multiplatform}}{{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isListContainer}}{{#isList}}kotlin.collections.List{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{classname}}.{{{nameInCamelCase}}}>{{/isListContainer}}{{^isListContainer}}{{classname}}.{{{nameInCamelCase}}}{{/isListContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}?

View File

@ -0,0 +1,12 @@
{{#description}}
/* {{{description}}} */
{{/description}}
{{^multiplatform}}
{{#moshi}}
@Json(name = "{{{vendorExtensions.x-base-name-literal}}}")
{{/moshi}}
{{#gson}}
@SerializedName("{{{vendorExtensions.x-base-name-literal}}}")
{{/gson}}
{{/multiplatform}}
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") @Required {{/multiplatform}}{{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isListContainer}}{{#isList}}kotlin.collections.List{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{classname}}.{{{nameInCamelCase}}}>{{/isListContainer}}{{^isListContainer}}{{classname}}.{{{nameInCamelCase}}}{{/isListContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}?{{/isNullable}}

View File

@ -27,7 +27,5 @@ data class ApiResponse (
val type: kotlin.String? = null,
@SerializedName("message")
val message: kotlin.String? = null
)
)

View File

@ -24,7 +24,5 @@ data class Category (
val id: kotlin.Long? = null,
@SerializedName("name")
val name: kotlin.String? = null
)
)

View File

@ -37,10 +37,8 @@ data class Order (
val status: Order.Status? = null,
@SerializedName("complete")
val complete: kotlin.Boolean? = null
)
) {
{
/**
* Order Status
* Values: placed,approved,delivered

View File

@ -39,10 +39,8 @@ data class Pet (
/* pet status in the store */
@SerializedName("status")
val status: Pet.Status? = null
)
) {
{
/**
* pet status in the store
* Values: available,pending,sold

View File

@ -24,7 +24,5 @@ data class Tag (
val id: kotlin.Long? = null,
@SerializedName("name")
val name: kotlin.String? = null
)
)

View File

@ -43,7 +43,5 @@ data class User (
/* User Status */
@SerializedName("userStatus")
val userStatus: kotlin.Int? = null
)
)

View File

@ -27,7 +27,5 @@ data class ApiResponse (
val type: kotlin.String? = null,
@Json(name = "message")
val message: kotlin.String? = null
)
)

View File

@ -24,7 +24,5 @@ data class Category (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
)

View File

@ -37,10 +37,8 @@ data class Order (
val status: Order.Status? = null,
@Json(name = "complete")
val complete: kotlin.Boolean? = null
)
) {
{
/**
* Order Status
* Values: placed,approved,delivered

View File

@ -39,10 +39,8 @@ data class Pet (
/* pet status in the store */
@Json(name = "status")
val status: Pet.Status? = null
)
) {
{
/**
* pet status in the store
* Values: available,pending,sold

View File

@ -24,7 +24,5 @@ data class Tag (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
)

View File

@ -43,7 +43,5 @@ data class User (
/* User Status */
@Json(name = "userStatus")
val userStatus: kotlin.Int? = null
)
)

View File

@ -28,7 +28,5 @@ data class ApiResponse (
val type: kotlin.String? = null,
@Json(name = "message")
val message: kotlin.String? = null
)
)

View File

@ -25,7 +25,5 @@ data class Category (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
)

View File

@ -38,10 +38,8 @@ data class Order (
val status: Order.Status? = null,
@Json(name = "complete")
val complete: kotlin.Boolean? = null
)
) {
{
/**
* Order Status
* Values: placed,approved,delivered

View File

@ -40,10 +40,8 @@ data class Pet (
/* pet status in the store */
@Json(name = "status")
val status: Pet.Status? = null
)
) {
{
/**
* pet status in the store
* Values: available,pending,sold

View File

@ -25,7 +25,5 @@ data class Tag (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
)

View File

@ -44,7 +44,5 @@ data class User (
/* User Status */
@Json(name = "userStatus")
val userStatus: kotlin.Int? = null
)
)

View File

@ -25,7 +25,5 @@ data class ApiResponse (
@SerialName(value = "code") val code: kotlin.Int? = null,
@SerialName(value = "type") val type: kotlin.String? = null,
@SerialName(value = "message") val message: kotlin.String? = null
)
)

View File

@ -23,7 +23,5 @@ import kotlinx.serialization.internal.CommonEnumSerializer
data class Category (
@SerialName(value = "id") val id: kotlin.Long? = null,
@SerialName(value = "name") val name: kotlin.String? = null
)
)

View File

@ -32,10 +32,8 @@ data class Order (
/* Order Status */
@SerialName(value = "status") val status: Order.Status? = null,
@SerialName(value = "complete") val complete: kotlin.Boolean? = null
)
) {
{
/**
* Order Status
* Values: placed,approved,delivered

View File

@ -34,10 +34,8 @@ data class Pet (
@SerialName(value = "tags") val tags: kotlin.Array<Tag>? = null,
/* pet status in the store */
@SerialName(value = "status") val status: Pet.Status? = null
)
) {
{
/**
* pet status in the store
* Values: available,pending,sold

View File

@ -23,7 +23,5 @@ import kotlinx.serialization.internal.CommonEnumSerializer
data class Tag (
@SerialName(value = "id") val id: kotlin.Long? = null,
@SerialName(value = "name") val name: kotlin.String? = null
)
)

View File

@ -36,7 +36,5 @@ data class User (
@SerialName(value = "phone") val phone: kotlin.String? = null,
/* User Status */
@SerialName(value = "userStatus") val userStatus: kotlin.Int? = null
)
)

View File

@ -27,7 +27,5 @@ internal data class ApiResponse (
val type: kotlin.String? = null,
@Json(name = "message")
val message: kotlin.String? = null
)
)

View File

@ -24,7 +24,5 @@ internal data class Category (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
)

View File

@ -37,10 +37,8 @@ internal data class Order (
val status: Order.Status? = null,
@Json(name = "complete")
val complete: kotlin.Boolean? = null
)
) {
{
/**
* Order Status
* Values: placed,approved,delivered

View File

@ -39,10 +39,8 @@ internal data class Pet (
/* pet status in the store */
@Json(name = "status")
val status: Pet.Status? = null
)
) {
{
/**
* pet status in the store
* Values: available,pending,sold

View File

@ -24,7 +24,5 @@ internal data class Tag (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
)

View File

@ -43,7 +43,5 @@ internal data class User (
/* User Status */
@Json(name = "userStatus")
val userStatus: kotlin.Int? = null
)
)

View File

@ -28,12 +28,10 @@ data class ApiResponse (
val type: kotlin.String? = null,
@Json(name = "message")
val message: kotlin.String? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
}

View File

@ -25,12 +25,10 @@ data class Category (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
}

View File

@ -38,13 +38,11 @@ data class Order (
val status: Order.Status? = null,
@Json(name = "complete")
val complete: kotlin.Boolean? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
/**
* Order Status
* Values: placed,approved,delivered

View File

@ -40,13 +40,11 @@ data class Pet (
/* pet status in the store */
@Json(name = "status")
val status: Pet.Status? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
/**
* pet status in the store
* Values: available,pending,sold

View File

@ -25,12 +25,10 @@ data class Tag (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
}

View File

@ -44,12 +44,10 @@ data class User (
/* User Status */
@Json(name = "userStatus")
val userStatus: kotlin.Int? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
}

View File

@ -27,7 +27,5 @@ data class ApiResponse (
val type: kotlin.String? = null,
@Json(name = "message")
val message: kotlin.String? = null
)
)

View File

@ -24,7 +24,5 @@ data class Category (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
)

View File

@ -37,10 +37,8 @@ data class Order (
val status: Order.Status? = null,
@Json(name = "complete")
val complete: kotlin.Boolean? = null
)
) {
{
/**
* Order Status
* Values: placed,approved,delivered

View File

@ -39,10 +39,8 @@ data class Pet (
/* pet status in the store */
@Json(name = "status")
val status: Pet.Status? = null
)
) {
{
/**
* pet status in the store
* Values: available,pending,sold

View File

@ -24,7 +24,5 @@ data class Tag (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
)

View File

@ -43,7 +43,5 @@ data class User (
/* User Status */
@Json(name = "userStatus")
val userStatus: kotlin.Int? = null
)
)

View File

@ -27,7 +27,5 @@ data class ApiResponse (
val type: kotlin.String? = null,
@Json(name = "message")
val message: kotlin.String? = null
)
)

View File

@ -24,7 +24,5 @@ data class Category (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
)

View File

@ -37,10 +37,8 @@ data class Order (
val status: Order.Status? = null,
@Json(name = "complete")
val complete: kotlin.Boolean? = null
)
) {
{
/**
* Order Status
* Values: placed,approved,delivered

View File

@ -39,10 +39,8 @@ data class Pet (
/* pet status in the store */
@Json(name = "status")
val status: Pet.Status? = null
)
) {
{
/**
* pet status in the store
* Values: available,pending,sold

View File

@ -24,7 +24,5 @@ data class Tag (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
)

View File

@ -43,7 +43,5 @@ data class User (
/* User Status */
@Json(name = "userStatus")
val userStatus: kotlin.Int? = null
)
)

View File

@ -28,12 +28,10 @@ data class ApiResponse (
val type: kotlin.String? = null,
@Json(name = "message")
val message: kotlin.String? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
}

View File

@ -25,12 +25,10 @@ data class Category (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
}

View File

@ -38,13 +38,11 @@ data class Order (
val status: Order.Status? = null,
@Json(name = "complete")
val complete: kotlin.Boolean? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
/**
* Order Status
* Values: placed,approved,delivered

View File

@ -27,26 +27,24 @@ import java.io.Serializable
*/
data class Pet (
@Json(name = "id")
val id: kotlin.Long? = null,
@Json(name = "category")
val category: Category? = null,
@Json(name = "name")
val name: kotlin.String,
@Json(name = "photoUrls")
val photoUrls: kotlin.Array<kotlin.String>,
@Json(name = "id")
val id: kotlin.Long? = null,
@Json(name = "category")
val category: Category? = null,
@Json(name = "tags")
val tags: kotlin.Array<Tag>? = null,
/* pet status in the store */
@Json(name = "status")
val status: Pet.Status? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
/**
* pet status in the store
* Values: available,pending,sold

View File

@ -25,12 +25,10 @@ data class Tag (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
}

View File

@ -44,12 +44,10 @@ data class User (
/* User Status */
@Json(name = "userStatus")
val userStatus: kotlin.Int? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
}

View File

@ -27,7 +27,5 @@ data class ApiResponse (
val type: kotlin.String? = null,
@Json(name = "message")
val message: kotlin.String? = null
)
)

View File

@ -24,7 +24,5 @@ data class Category (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
)

View File

@ -37,10 +37,8 @@ data class Order (
val status: Order.Status? = null,
@Json(name = "complete")
val complete: kotlin.Boolean? = null
)
) {
{
/**
* Order Status
* Values: placed,approved,delivered

View File

@ -39,10 +39,8 @@ data class Pet (
/* pet status in the store */
@Json(name = "status")
val status: Pet.Status? = null
)
) {
{
/**
* pet status in the store
* Values: available,pending,sold

View File

@ -24,7 +24,5 @@ data class Tag (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
)

View File

@ -43,7 +43,5 @@ data class User (
/* User Status */
@Json(name = "userStatus")
val userStatus: kotlin.Int? = null
)
)

View File

@ -28,12 +28,10 @@ data class ApiResponse (
val type: kotlin.String? = null,
@Json(name = "message")
val message: kotlin.String? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
}

View File

@ -25,12 +25,10 @@ data class Category (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
}

View File

@ -38,13 +38,11 @@ data class Order (
val status: Order.Status? = null,
@Json(name = "complete")
val complete: kotlin.Boolean? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
/**
* Order Status
* Values: placed,approved,delivered

View File

@ -40,13 +40,11 @@ data class Pet (
/* pet status in the store */
@Json(name = "status")
val status: Pet.Status? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
/**
* pet status in the store
* Values: available,pending,sold

View File

@ -25,12 +25,10 @@ data class Tag (
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
}

View File

@ -44,12 +44,10 @@ data class User (
/* User Status */
@Json(name = "userStatus")
val userStatus: kotlin.Int? = null
)
: Serializable
{
) : Serializable {
companion object {
private const val serialVersionUID: Long = 123
}
}