Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix list in kotlin client templates #18891

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,20 @@ import java.io.IOException
{{^vendorExtensions.x-duplicated-data-type}}
// check if the actual instance is of the type `{{{dataType}}}`
if (value.actualInstance is {{#isArray}}List<*>{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}) {
{{#isPrimitiveType}}
val primitive = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(value.actualInstance as {{{dataType}}}?).getAsJsonPrimitive()
elementAdapter.write(out, primitive)
return
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isArray}}
List<?> list = (List<?>) value.actualInstance
val list = value.actualInstance as List<Any>
if (list.get(0) is {{{items.dataType}}}) {
val array = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(value.actualInstance as {{{dataType}}}?).getAsJsonArray()
elementAdapter.write(out, array)
return
}
{{/isArray}}
{{/isPrimitiveType}}
{{^isArray}}
{{#isPrimitiveType}}
val primitive = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(value.actualInstance as {{{dataType}}}?).getAsJsonPrimitive()
elementAdapter.write(out, primitive)
return
{{/isPrimitiveType}}
{{^isPrimitiveType}}
val element = adapter{{{dataType}}}.toJsonTree(value.actualInstance as {{{dataType}}}?)
elementAdapter.write(out, element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ import {{packageName}}.infrastructure.ITransformForStorage
{{#required}}
// ensure the json data is an array
if (!jsonObj.get("{{{baseName}}}").isJsonArray) {
throw new IllegalArgumentException(String.format("Expected the field `{{{baseName}}}` to be an array in the JSON string but got `%s`", jsonObj["{{{baseName}}}"].toString()))
throw IllegalArgumentException(String.format("Expected the field `{{{baseName}}}` to be an array in the JSON string but got `%s`", jsonObj["{{{baseName}}}"].toString()))
}

JsonArray jsonArray{{name}} = jsonObj.getAsJsonArray("{{{baseName}}}")
val jsonArray{{name}} = jsonObj.getAsJsonArray("{{{baseName}}}")
// validate the required field `{{{baseName}}}` (array)
for (i in 0 until jsonArray{{name}}.size()) {
{{{items.dataType}}}.validateJsonElement(jsonArray{{name}}.get(i))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,20 @@ import java.io.IOException
{{^vendorExtensions.x-duplicated-data-type}}
// check if the actual instance is of the type `{{{dataType}}}`
if (value.actualInstance is {{#isArray}}List<*>{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}) {
{{#isPrimitiveType}}
val primitive = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(value.actualInstance as {{{dataType}}}?).getAsJsonPrimitive()
elementAdapter.write(out, primitive)
return
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isArray}}
List<?> list = (List<?>) value.actualInstance
val list = value.actualInstance as List<Any>
if (list.get(0) is {{{items.dataType}}}) {
val array = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(value.actualInstance as {{{dataType}}}?).getAsJsonArray()
elementAdapter.write(out, array)
return
}
{{/isArray}}
{{/isPrimitiveType}}
{{^isArray}}
{{#isPrimitiveType}}
val primitive = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(value.actualInstance as {{{dataType}}}?).getAsJsonPrimitive()
elementAdapter.write(out, primitive)
return
{{/isPrimitiveType}}
{{^isPrimitiveType}}
val element = adapter{{{dataType}}}.toJsonTree(value.actualInstance as {{{dataType}}}?)
elementAdapter.write(out, element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ data class ApiAnyOfUserOrPetOrArrayString(var actualInstance: Any? = null) {
}
// check if the actual instance is of the type `kotlin.collections.List<kotlin.String>`
if (value.actualInstance is List<*>) {
val primitive = adapterkotlincollectionsListkotlinString.toJsonTree(value.actualInstance as kotlin.collections.List<kotlin.String>?).getAsJsonPrimitive()
elementAdapter.write(out, primitive)
return
val list = value.actualInstance as List<Any>
if (list.get(0) is kotlin.String) {
val array = adapterkotlincollectionsListkotlinString.toJsonTree(value.actualInstance as kotlin.collections.List<kotlin.String>?).getAsJsonArray()
elementAdapter.write(out, array)
return
}
}
throw IOException("Failed to serialize as the type doesn't match anyOf schemas: ApiPet, ApiUser, kotlin.collections.List<kotlin.String>")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ data class ApiUserOrPetOrArrayString(var actualInstance: Any? = null) {
}
// check if the actual instance is of the type `kotlin.collections.List<kotlin.String>`
if (value.actualInstance is List<*>) {
val primitive = adapterkotlincollectionsListkotlinString.toJsonTree(value.actualInstance as kotlin.collections.List<kotlin.String>?).getAsJsonPrimitive()
elementAdapter.write(out, primitive)
return
val list = value.actualInstance as List<Any>
if (list.get(0) is kotlin.String) {
val array = adapterkotlincollectionsListkotlinString.toJsonTree(value.actualInstance as kotlin.collections.List<kotlin.String>?).getAsJsonArray()
elementAdapter.write(out, array)
return
}
}
throw IOException("Failed to serialize as the type doesn't match oneOf schemas: ApiPet, ApiUser, kotlin.collections.List<kotlin.String>")
}
Expand Down
Loading