forked from loafle/openapi-generator-original
[Kotlin-Client][JVM-OkHttp] Override parameter enum's toString() method to use its value (#19053)
When using the JVM implementation of OkHttp with a Kotlin client, you may encounter issues with the toString() method of enum parameters. By default, the toString() method of an enum returns the name of the enum value, not its value. To fix this issue, you can override the toString() method of your enum to return its value instead of its name.
This commit is contained in:
@@ -50,7 +50,16 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient
|
||||
enum class QueryDefaultEnumFindPetsByStatus(val value: kotlin.String) {
|
||||
@Json(name = "A") A("A"),
|
||||
@Json(name = "B") B("B"),
|
||||
@Json(name = "C") C("C")
|
||||
@Json(name = "C") C("C");
|
||||
|
||||
/**
|
||||
* Override [toString()] to avoid using the enum variable name as the value, and instead use
|
||||
* the actual value defined in the API spec file.
|
||||
*
|
||||
* This solves a problem when the variable name and its value are different, and ensures that
|
||||
* the client sends the correct enum values to the server always.
|
||||
*/
|
||||
override fun toString(): kotlin.String = "$value"
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +68,16 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient
|
||||
enum class HeaderDefaultEnumFindPetsByStatus(val value: kotlin.String) {
|
||||
@Json(name = "A") A("A"),
|
||||
@Json(name = "B") B("B"),
|
||||
@Json(name = "C") C("C")
|
||||
@Json(name = "C") C("C");
|
||||
|
||||
/**
|
||||
* Override [toString()] to avoid using the enum variable name as the value, and instead use
|
||||
* the actual value defined in the API spec file.
|
||||
*
|
||||
* This solves a problem when the variable name and its value are different, and ensures that
|
||||
* the client sends the correct enum values to the server always.
|
||||
*/
|
||||
override fun toString(): kotlin.String = "$value"
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +86,16 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient
|
||||
enum class CookieDefaultEnumFindPetsByStatus(val value: kotlin.String) {
|
||||
@Json(name = "A") A("A"),
|
||||
@Json(name = "B") B("B"),
|
||||
@Json(name = "C") C("C")
|
||||
@Json(name = "C") C("C");
|
||||
|
||||
/**
|
||||
* Override [toString()] to avoid using the enum variable name as the value, and instead use
|
||||
* the actual value defined in the API spec file.
|
||||
*
|
||||
* This solves a problem when the variable name and its value are different, and ensures that
|
||||
* the client sends the correct enum values to the server always.
|
||||
*/
|
||||
override fun toString(): kotlin.String = "$value"
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user