Skip to content

Commit 0cb88ce

Browse files
authored
[KOTLIN] add modelMutable additional properties parser (#11332)
* [kotlin] add modelMutable parser * [kotlin] fix kotlin vertx samples
1 parent 90972c6 commit 0cb88ce

File tree

7 files changed

+35
-31
lines changed

7 files changed

+35
-31
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ public void processOpts() {
416416
LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).");
417417
}
418418

419+
if (additionalProperties.containsKey(MODEL_MUTABLE)) {
420+
additionalProperties.put(MODEL_MUTABLE, Boolean.parseBoolean(additionalProperties.get(MODEL_MUTABLE).toString()));
421+
}
422+
419423
if (additionalProperties.containsKey(CodegenConstants.ENUM_PROPERTY_NAMING)) {
420424
setEnumPropertyNaming((String) additionalProperties.get(CodegenConstants.ENUM_PROPERTY_NAMING));
421425
}

samples/server/petstore/kotlin/vertx/src/main/kotlin/org/openapitools/server/api/model/Category.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import com.fasterxml.jackson.annotation.JsonInclude
2424
@JsonInclude(JsonInclude.Include.NON_NULL)
2525
@JsonIgnoreProperties(ignoreUnknown = true)
2626
data class Category (
27-
var id: kotlin.Long? = null,
28-
var name: kotlin.String? = null
27+
val id: kotlin.Long? = null,
28+
val name: kotlin.String? = null
2929
) {
3030

3131
}

samples/server/petstore/kotlin/vertx/src/main/kotlin/org/openapitools/server/api/model/ModelApiResponse.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import com.fasterxml.jackson.annotation.JsonInclude
2525
@JsonInclude(JsonInclude.Include.NON_NULL)
2626
@JsonIgnoreProperties(ignoreUnknown = true)
2727
data class ModelApiResponse (
28-
var code: kotlin.Int? = null,
29-
var type: kotlin.String? = null,
30-
var message: kotlin.String? = null
28+
val code: kotlin.Int? = null,
29+
val type: kotlin.String? = null,
30+
val message: kotlin.String? = null
3131
) {
3232

3333
}

samples/server/petstore/kotlin/vertx/src/main/kotlin/org/openapitools/server/api/model/Order.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ import com.fasterxml.jackson.annotation.JsonInclude
2828
@JsonInclude(JsonInclude.Include.NON_NULL)
2929
@JsonIgnoreProperties(ignoreUnknown = true)
3030
data class Order (
31-
var id: kotlin.Long? = null,
32-
var petId: kotlin.Long? = null,
33-
var quantity: kotlin.Int? = null,
34-
var shipDate: java.time.OffsetDateTime? = null,
31+
val id: kotlin.Long? = null,
32+
val petId: kotlin.Long? = null,
33+
val quantity: kotlin.Int? = null,
34+
val shipDate: java.time.OffsetDateTime? = null,
3535
/* Order Status */
36-
var status: Order.Status? = null,
37-
var complete: kotlin.Boolean? = false
36+
val status: Order.Status? = null,
37+
val complete: kotlin.Boolean? = false
3838
) {
3939

4040
/**

samples/server/petstore/kotlin/vertx/src/main/kotlin/org/openapitools/server/api/model/Pet.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ import com.fasterxml.jackson.annotation.JsonInclude
3030
@JsonInclude(JsonInclude.Include.NON_NULL)
3131
@JsonIgnoreProperties(ignoreUnknown = true)
3232
data class Pet (
33-
@SerializedName("name") private var _name: kotlin.String?,
34-
@SerializedName("photoUrls") private var _photoUrls: kotlin.Array<kotlin.String>?,
35-
var id: kotlin.Long? = null,
36-
var category: Category? = null,
37-
var tags: kotlin.Array<Tag>? = null,
33+
@SerializedName("name") private val _name: kotlin.String?,
34+
@SerializedName("photoUrls") private val _photoUrls: kotlin.Array<kotlin.String>?,
35+
val id: kotlin.Long? = null,
36+
val category: Category? = null,
37+
val tags: kotlin.Array<Tag>? = null,
3838
/* pet status in the store */
39-
var status: Pet.Status? = null
39+
val status: Pet.Status? = null
4040
) {
4141

4242
/**
@@ -53,9 +53,9 @@ data class Pet (
5353

5454
}
5555

56-
var name get() = _name ?: throw IllegalArgumentException("name is required")
57-
set(value){ _name = value }
58-
var photoUrls get() = _photoUrls ?: throw IllegalArgumentException("photoUrls is required")
59-
set(value){ _photoUrls = value }
56+
val name get() = _name ?: throw IllegalArgumentException("name is required")
57+
58+
val photoUrls get() = _photoUrls ?: throw IllegalArgumentException("photoUrls is required")
59+
6060
}
6161

samples/server/petstore/kotlin/vertx/src/main/kotlin/org/openapitools/server/api/model/Tag.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import com.fasterxml.jackson.annotation.JsonInclude
2424
@JsonInclude(JsonInclude.Include.NON_NULL)
2525
@JsonIgnoreProperties(ignoreUnknown = true)
2626
data class Tag (
27-
var id: kotlin.Long? = null,
28-
var name: kotlin.String? = null
27+
val id: kotlin.Long? = null,
28+
val name: kotlin.String? = null
2929
) {
3030

3131
}

samples/server/petstore/kotlin/vertx/src/main/kotlin/org/openapitools/server/api/model/User.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ import com.fasterxml.jackson.annotation.JsonInclude
3030
@JsonInclude(JsonInclude.Include.NON_NULL)
3131
@JsonIgnoreProperties(ignoreUnknown = true)
3232
data class User (
33-
var id: kotlin.Long? = null,
34-
var username: kotlin.String? = null,
35-
var firstName: kotlin.String? = null,
36-
var lastName: kotlin.String? = null,
37-
var email: kotlin.String? = null,
38-
var password: kotlin.String? = null,
39-
var phone: kotlin.String? = null,
33+
val id: kotlin.Long? = null,
34+
val username: kotlin.String? = null,
35+
val firstName: kotlin.String? = null,
36+
val lastName: kotlin.String? = null,
37+
val email: kotlin.String? = null,
38+
val password: kotlin.String? = null,
39+
val phone: kotlin.String? = null,
4040
/* User Status */
41-
var userStatus: kotlin.Int? = null
41+
val userStatus: kotlin.Int? = null
4242
) {
4343

4444
}

0 commit comments

Comments
 (0)