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}} 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"])