From 8e9ede630057fc6fe2f33aad0cc2ecb5c1a3be00 Mon Sep 17 00:00:00 2001 From: andreas-umbricht Date: Thu, 22 May 2025 16:13:37 +0200 Subject: [PATCH 1/2] Primitive array items validity check --- .../main/resources/kotlin-client/data_class.mustache | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache index 4b3e1ae3e72b..1cc3e8d299c0 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache @@ -291,6 +291,16 @@ import {{packageName}}.infrastructure.ITransformForStorage String.format("Expected the field `{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}` to be an array in the JSON string but got `%s`", jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"].toString()) } {{/required}} + {{#items.isPrimitiveType}} + // ensure the items in json array are primitive + if (jsonObj["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"] != null) { + for (i in 0 until jsonObj.getAsJsonArray("{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}").size()) { + require(jsonObj.getAsJsonArray("{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}").get(i).isJsonPrimitive) { + String.format("Expected the property in array `{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}` to be primitive") + } + } + } + {{/items.isPrimitiveType}} {{/items.isModel}} {{/isArray}} {{^isContainer}} From 91b897cd0b6a644d3cdedf715b3a62df5c48d129 Mon Sep 17 00:00:00 2001 From: andreas-umbricht Date: Mon, 26 May 2025 15:55:24 +0200 Subject: [PATCH 2/2] Update samples --- .../main/kotlin/org/openapitools/client/models/ApiPet.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiPet.kt b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiPet.kt index f47705a67d6e..7d6987037d10 100644 --- a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiPet.kt +++ b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiPet.kt @@ -151,6 +151,14 @@ data class ApiPet ( require(jsonObj["photoUrls"].isJsonArray()) { String.format("Expected the field `photoUrls` to be an array in the JSON string but got `%s`", jsonObj["photoUrls"].toString()) } + // ensure the items in json array are primitive + if (jsonObj["photoUrls"] != null) { + for (i in 0 until jsonObj.getAsJsonArray("photoUrls").size()) { + require(jsonObj.getAsJsonArray("photoUrls").get(i).isJsonPrimitive) { + String.format("Expected the property in array `photoUrls` to be primitive") + } + } + } // validate the optional field `category` if (jsonObj["category"] != null && !jsonObj["category"].isJsonNull) { ApiCategory.validateJsonElement(jsonObj["category"])