Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !14045
Something went wrong while fetching comments. Please try again.

update ktor multiplatform serialization issue

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Administrator requested to merge github/fork/C0deH0use/fix/kotlin-multiplatform-fix-serialization into master 2 years ago
  • Overview 3
  • Commits 2
  • Pipelines 1
  • Changes 135

Created by: Marek00Malik

update ktor multiplatform serialization issue - #14044

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (6.3.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the [@jimmidyson, @dr4ke616 @karismann @Zomzog @andrewemery @4brunu @yuantao-yin ]
Compare
  • version 1
    81d809e0
    2 years ago

  • master (HEAD)

and
  • latest version
    81d809e0
    2 commits, 2 years ago

  • version 1
    81d809e0
    2 commits, 2 years ago

135 files
+ 1352
- 739

    Preferences

    File browser
    Compare changes
modules/openapi-g‎enerator/src/main‎
java/org/openapitoo‎ls/codegen/languages‎
KotlinClient‎Codegen.java‎ +4 -0
resources/k‎otlin-client‎
jvm-common/i‎nfrastructure‎
OffsetDateTimeAd‎apter.kt.mustache‎ +45 -6
libr‎aries‎
jvm-ktor/in‎frastructure‎
ApiClient.‎kt.mustache‎ +9 -0
Errors.kt‎.mustache‎ +18 -0
HttpResponse‎.kt.mustache‎ +10 -2
HttpResponseExten‎sions.kt.mustache‎ +24 -0
jvm-o‎khttp‎
api.mu‎stache‎ +2 -2
multiplatform/‎infrastructure‎
ApiClient.‎kt.mustache‎ +2 -0
build.grad‎le.mustache‎ +1 -1
samples/cli‎ent/petstore‎
kot‎lin‎
s‎rc‎
main/kotlin/org/o‎penapitools/client‎
ap‎is‎
PetA‎pi.kt‎ +16 -16
Store‎Api.kt‎ +8 -8
UserA‎pi.kt‎ +16 -16
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
test/kotlin/org/o‎penapitools/client‎
PetApi‎Test.kt‎ +0 -104
StoreAp‎iTest.kt‎ +0 -48
build.‎gradle‎ +0 -1
kotlin-allOff‎-discriminator‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
BirdA‎pi.kt‎ +2 -2
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
gra‎dlew‎ +0 -0
kotlin-array-simple‎-string-jvm-okhttp3‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
Defaul‎tApi.kt‎ +2 -2
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-array-simple‎-string-jvm-okhttp4‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
Defaul‎tApi.kt‎ +2 -2
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-bigdecima‎l-default-okhttp4‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
Defaul‎tApi.kt‎ +2 -2
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-default-v‎alues-jvm-okhttp3‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
Defaul‎tApi.kt‎ +2 -2
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-default-v‎alues-jvm-okhttp4‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
Defaul‎tApi.kt‎ +2 -2
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-default-va‎lues-jvm-retrofit2‎
src/main/…/…/…/cli‎ent/infrastructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-enum-‎default-value‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
Defaul‎tApi.kt‎ +2 -2
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotli‎n-gson‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
PetA‎pi.kt‎ +16 -16
Store‎Api.kt‎ +8 -8
UserA‎pi.kt‎ +16 -16
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +16 -4
build.‎gradle‎ +0 -1
kotlin-‎jackson‎
src/main/kotlin‎/…/…/client/apis‎
PetA‎pi.kt‎ +16 -16
Store‎Api.kt‎ +8 -8
UserA‎pi.kt‎ +16 -16
build.‎gradle‎ +0 -1
kotlin-json-r‎equest-string‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
PetA‎pi.kt‎ +16 -16
Store‎Api.kt‎ +8 -8
UserA‎pi.kt‎ +16 -16
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +15 -1
build.‎gradle‎ +0 -1
kotlin-jvm‎-ktor-gson‎
.openapi-‎generator‎
FI‎LES‎ +7 -0
src/main/…/…/…/cli‎ent/infrastructure‎
ApiCli‎ent.kt‎ +9 -0
ByteArray‎Adapter.kt‎ +33 -0
Erro‎rs.kt‎ +18 -0
HttpRes‎ponse.kt‎ +10 -2
HttpResponse‎Extensions.kt‎ +24 -0
LocalDate‎Adapter.kt‎ +35 -0
LocalDateTi‎meAdapter.kt‎ +35 -0
OffsetDateTi‎meAdapter.kt‎ +47 -0
Serial‎izer.kt‎ +22 -0
build.‎gradle‎ +1 -1
kotlin-jvm-‎ktor-jackson‎
.openapi-‎generator‎
FI‎LES‎ +3 -0
src/main/…/…/…/cli‎ent/infrastructure‎
ApiCli‎ent.kt‎ +2 -0
Erro‎rs.kt‎ +18 -0
HttpRes‎ponse.kt‎ +10 -2
HttpResponse‎Extensions.kt‎ +24 -0
Serial‎izer.kt‎ +14 -0
build.‎gradle‎ +1 -1
kotlin-jvm-okh‎ttp4-coroutines‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
PetA‎pi.kt‎ +16 -16
Store‎Api.kt‎ +8 -8
UserA‎pi.kt‎ +16 -16
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +16 -4
build.‎gradle‎ +0 -1
kotlin-jvm‎-vertx-gson‎
src/main/…/…/…/cli‎ent/infrastructure‎
OffsetDateTi‎meAdapter.kt‎ +16 -4
build.‎gradle‎ +0 -1
kotlin-jvm-v‎ertx-jackson‎
build.‎gradle‎ +0 -1
kotlin-jvm-vertx-‎jackson-coroutines‎
build.‎gradle‎ +0 -1
kotlin-jvm-‎vertx-moshi‎
src/main/…/…/…/cli‎ent/infrastructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-jvm-voll‎ey/…/…/…/…/…/…/…‎
OffsetDateTi‎meAdapter.kt‎ +16 -4
kotlin-mo‎delMutable‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
PetA‎pi.kt‎ +16 -16
Store‎Api.kt‎ +8 -8
UserA‎pi.kt‎ +16 -16
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-mos‎hi-codegen‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
PetA‎pi.kt‎ +16 -16
Store‎Api.kt‎ +8 -8
UserA‎pi.kt‎ +16 -16
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-multi‎platform/src‎
commonMain/kotlin/…‎/…/…/infrastructure‎
ApiCli‎ent.kt‎ +2 -0
jvmTest/k‎otlin/util‎
PetShop‎Test.kt‎ +13 -0
kotlin-n‎onpublic‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
PetA‎pi.kt‎ +16 -16
Store‎Api.kt‎ +8 -8
UserA‎pi.kt‎ +16 -16
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-‎nullable‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
PetA‎pi.kt‎ +16 -16
Store‎Api.kt‎ +8 -8
UserA‎pi.kt‎ +16 -16
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-‎okhttp3‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
PetA‎pi.kt‎ +16 -16
Store‎Api.kt‎ +8 -8
UserA‎pi.kt‎ +16 -16
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-r‎etrofit2‎
src/main/…/…/…/cli‎ent/infrastructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-retrofit2-ko‎tlinx_serialization‎
src/main/…/…/…/cli‎ent/infrastructure‎
OffsetDateTi‎meAdapter.kt‎ +15 -1
build.‎gradle‎ +0 -1
kotlin-ret‎rofit2-rx3‎
src/main/…/…/…/cli‎ent/infrastructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin‎-string‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
PetA‎pi.kt‎ +16 -16
Store‎Api.kt‎ +8 -8
UserA‎pi.kt‎ +16 -16
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-t‎hreetenbp‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
PetA‎pi.kt‎ +16 -16
Store‎Api.kt‎ +8 -8
UserA‎pi.kt‎ +16 -16
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +14 -1
build.‎gradle‎ +0 -1
kotlin-upp‎ercase-enum‎
src/main/kotlin/org‎/openapitools/client‎
ap‎is‎
EnumA‎pi.kt‎ +2 -2
infrast‎ructure‎
OffsetDateTi‎meAdapter.kt‎ +15 -1
build.‎gradle‎ +0 -1
…/…/…/…‎/…/…/…/…‎
OffsetDateTi‎meAdapter.kt‎ +16 -4
…/…/…/…‎/…/…/…/…‎
ApiCli‎ent.kt‎ +2 -0
…/…/…/…‎/…/…/…/…‎
ApiCli‎ent.kt‎ +2 -0
…/…/…/…‎/…/…/…/…‎
OffsetDateTi‎meAdapter.kt‎ +16 -4
…/…/…/…‎/…/…/…/…‎
ApiCli‎ent.kt‎ +2 -0
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java
+ 4
- 0
  • View file @ 22036c02

  • Edit in single-file editor

  • Open in Web IDE


@@ -661,6 +661,8 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
supportingFiles.add(new SupportingFile("infrastructure/ApiAbstractions.kt.mustache", infrastructureFolder, "ApiAbstractions.kt"));
supportingFiles.add(new SupportingFile("infrastructure/ApiClient.kt.mustache", infrastructureFolder, "ApiClient.kt"));
supportingFiles.add(new SupportingFile("infrastructure/HttpResponse.kt.mustache", infrastructureFolder, "HttpResponse.kt"));
supportingFiles.add(new SupportingFile("infrastructure/HttpResponseExtensions.kt.mustache", infrastructureFolder, "HttpResponseExtensions.kt"));
supportingFiles.add(new SupportingFile("infrastructure/Errors.kt.mustache", infrastructureFolder, "Errors.kt"));
supportingFiles.add(new SupportingFile("infrastructure/RequestConfig.kt.mustache", infrastructureFolder, "RequestConfig.kt"));
supportingFiles.add(new SupportingFile("infrastructure/RequestMethod.kt.mustache", infrastructureFolder, "RequestMethod.kt"));
@@ -669,6 +671,8 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.kt.mustache", authFolder, "HttpBasicAuth.kt"));
supportingFiles.add(new SupportingFile("auth/HttpBearerAuth.kt.mustache", authFolder, "HttpBearerAuth.kt"));
supportingFiles.add(new SupportingFile("auth/OAuth.kt.mustache", authFolder, "OAuth.kt"));
addSupportingSerializerAdapters(infrastructureFolder);
}
/**
modules/openapi-generator/src/main/resources/kotlin-client/jvm-common/infrastructure/OffsetDateTimeAdapter.kt.mustache
+ 45
- 6
  • View file @ 22036c02

  • Edit in single-file editor

  • Open in Web IDE


@@ -38,9 +38,22 @@ import org.threeten.bp.format.DateTimeFormatter
@FromJson
fun fromJson(value: String): OffsetDateTime {
return OffsetDateTime.parse(value, DateTimeFormatter.ISO_OFFSET_DATE_TIME)
return OffsetDateTime.parse(tryFormatDateTime(value), DateTimeFormatter.ISO_OFFSET_DATE_TIME)
}
private fun tryFormatDateTime(stringValue: String): String {
val offset = stringValue.substringAfter("+")
return when (offset.length) {
4 -> fixOffsetValue(stringValue, offset)
else -> stringValue
}
}
private fun fixOffsetValue(stringValue: String = "0000", offset: String): String {
val offsetChars = offset.toCharArray().toMutableList()
offsetChars.add(2, ':')
return stringValue.replaceAfter("+", offsetChars.joinToString(""))
}
}
{{/moshi}}
{{#gson}}
@@ -58,16 +71,28 @@ import org.threeten.bp.format.DateTimeFormatter
override fun read(out: JsonReader?): OffsetDateTime? {
out ?: return null
when (out.peek()) {
return when (out.peek()) {
NULL -> {
out.nextNull()
return null
}
else -> {
return OffsetDateTime.parse(out.nextString(), formatter)
}
else -> OffsetDateTime.parse(tryFormatDateTime(out.nextString()), formatter)
}
}
private fun tryFormatDateTime(stringValue: String): String {
val offset = stringValue.substringAfter("+")
return when (offset.length) {
4 -> fixOffsetValue(stringValue, offset)
else -> stringValue
}
}
private fun fixOffsetValue(stringValue: String = "0000", offset: String): String {
val offsetChars = offset.toCharArray().toMutableList()
offsetChars.add(2, ':')
return stringValue.replaceAfter("+", offsetChars.joinToString(""))
}
}
{{/gson}}
{{#kotlinx_serialization}}
@@ -80,7 +105,21 @@ import org.threeten.bp.format.DateTimeFormatter
}
override fun deserialize(decoder: Decoder): OffsetDateTime {
return OffsetDateTime.parse(decoder.decodeString(), DateTimeFormatter.ISO_OFFSET_DATE_TIME)
return OffsetDateTime.parse(tryFormatDateTime(decoder.decodeString()), DateTimeFormatter.ISO_OFFSET_DATE_TIME)
}
private fun tryFormatDateTime(stringValue: String): String {
val offset = stringValue.substringAfter("+")
return when (offset.length) {
4 -> fixOffsetValue(stringValue, offset)
else -> stringValue
}
}
private fun fixOffsetValue(stringValue: String = "0000", offset: String): String {
val offsetChars = offset.toCharArray().toMutableList()
offsetChars.add(2, ':')
return stringValue.replaceAfter("+", offsetChars.joinToString(""))
}
}
{{/kotlinx_serialization}}
\ No newline at end of file
modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-ktor/infrastructure/ApiClient.kt.mustache
+ 9
- 0
  • View file @ 22036c02

  • Edit in single-file editor

  • Open in Web IDE


@@ -21,10 +21,14 @@ import io.ktor.http.content.PartData
import io.ktor.http.encodeURLQueryComponent
import io.ktor.http.encodedPath
import io.ktor.http.takeFrom
import io.ktor.http.ContentType.Application
{{#gson}}
import io.ktor.serialization.gson.*
import com.google.gson.GsonBuilder
import java.text.DateFormat
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.OffsetDateTime
{{/gson}}
{{#jackson}}
import io.ktor.serialization.jackson.*
@@ -85,6 +89,10 @@ import {{packageName}}.auth.*
{{#gson}}
val JSON_DEFAULT : GsonBuilder.() -> Unit = {
setDateFormat(DateFormat.LONG)
registerTypeAdapter(OffsetDateTime::class.java, OffsetDateTimeAdapter())
registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeAdapter())
registerTypeAdapter(LocalDate::class.java, LocalDateAdapter())
registerTypeAdapter(ByteArray::class.java, ByteArrayAdapter())
setPrettyPrinting()
}
{{/gson}}
@@ -196,6 +204,7 @@ import {{packageName}}.auth.*
this.method = requestConfig.method.httpMethod
headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) }
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) {
this.contentType(Application.Json)
setBody(body)
}
}
modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-ktor/infrastructure/Errors.kt.mustache 0 → 100644
+ 18
- 0
  • View file @ 22036c02

  • Edit in single-file editor

  • Open in Web IDE

@file:Suppress("unused")
package {{packageName}}.infrastructure
import java.lang.RuntimeException
{{#nonPublicApi}}internal {{/nonPublicApi}}open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: io.ktor.client.statement.HttpResponse? = null) : RuntimeException(message) {
{{#nonPublicApi}}internal {{/nonPublicApi}}companion object {
private const val serialVersionUID: Long = 123L
}
}
{{#nonPublicApi}}internal {{/nonPublicApi}}open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: io.ktor.client.statement.HttpResponse? = null) : RuntimeException(message) {
{{#nonPublicApi}}internal {{/nonPublicApi}}companion object {
private const val serialVersionUID: Long = 456L
}
}
\ No newline at end of file
modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-ktor/infrastructure/HttpResponse.kt.mustache
+ 10
- 2
  • View file @ 22036c02

  • Edit in single-file editor

  • Open in Web IDE


@@ -2,8 +2,11 @@ package {{packageName}}.infrastructure
import io.ktor.http.Headers
import io.ktor.http.isSuccess
import io.ktor.util.InternalAPI
import io.ktor.util.reflect.TypeInfo
import io.ktor.util.reflect.typeInfo
import io.ktor.utils.io.readUTF8Line
{{#nonPublicApi}}internal {{/nonPublicApi}}open class HttpResponse<T : Any>(val response: io.ktor.client.statement.HttpResponse, val provider: BodyProvider<T>) {
val status: Int = response.status.value
@@ -26,10 +29,15 @@ import io.ktor.util.reflect.typeInfo
suspend fun <V : Any> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V
}
@OptIn(InternalAPI::class)
{{#nonPublicApi}}internal {{/nonPublicApi}}class TypedBodyProvider<T : Any>(private val type: TypeInfo) : BodyProvider<T> {
@Suppress("UNCHECKED_CAST")
override suspend fun body(response: io.ktor.client.statement.HttpResponse): T =
response.call.body(type) as T
override suspend fun body(response: io.ktor.client.statement.HttpResponse): T = when {
response.status.isSuccess() -> response.call.body(type) as T
response.isClientError -> throw ClientException("Client error : ${response.status.value} ${response.content.readUTF8Line()}", response.status.value, response)
response.isServerError -> throw ServerException("Server error : ${response.status.value} ${response.content.readUTF8Line()}", response.status.value, response)
else -> throw RuntimeException()
}
@Suppress("UNCHECKED_CAST")
override suspend fun <V : Any> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V =
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference:
Source branch: github/fork/C0deH0use/fix/kotlin-multiplatform-fix-serialization

Menu

Explore Projects Groups Snippets