Skip to content

Commit 7d1e999

Browse files
[Kotlin] Allow other content-types when only interested in status-code / Unit (#19801)
* Allow Unit response * Updating samples * Improve comment for Unit shortcut
1 parent 9a0fc59 commit 7d1e999

File tree

21 files changed

+105
-42
lines changed
  • modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure
  • samples/client
    • others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure
    • petstore
      • kotlin/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure
      • kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure

21 files changed

+105
-42
lines changed

modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache

+5-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,11 @@ import com.squareup.moshi.adapter
167167
val body = response.body
168168
if(body == null) {
169169
return null
170-
}
171-
if (T::class.java == File::class.java) {
170+
} else if (T::class.java == Unit::class.java) {
171+
// No need to parse the body when we're not interested in the body
172+
// Useful when API is returning other Content-Type
173+
return null
174+
} else if (T::class.java == File::class.java) {
172175
// return tempFile
173176
val contentDisposition = response.header("Content-Disposition")
174177

samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-allOff-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
124124
val body = response.body
125125
if(body == null) {
126126
return null
127-
}
128-
if (T::class.java == File::class.java) {
127+
} else if (T::class.java == Unit::class.java) {
128+
// No need to parse the body when we're not interested in the body
129+
// Useful when API is returning other Content-Type
130+
return null
131+
} else if (T::class.java == File::class.java) {
129132
// return tempFile
130133
val contentDisposition = response.header("Content-Disposition")
131134

samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
124124
val body = response.body
125125
if(body == null) {
126126
return null
127-
}
128-
if (T::class.java == File::class.java) {
127+
} else if (T::class.java == Unit::class.java) {
128+
// No need to parse the body when we're not interested in the body
129+
// Useful when API is returning other Content-Type
130+
return null
131+
} else if (T::class.java == File::class.java) {
129132
// return tempFile
130133
val contentDisposition = response.header("Content-Disposition")
131134

samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
126126
val body = response.body
127127
if(body == null) {
128128
return null
129-
}
130-
if (T::class.java == File::class.java) {
129+
} else if (T::class.java == Unit::class.java) {
130+
// No need to parse the body when we're not interested in the body
131+
// Useful when API is returning other Content-Type
132+
return null
133+
} else if (T::class.java == File::class.java) {
131134
// return tempFile
132135
val contentDisposition = response.header("Content-Disposition")
133136

samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
127127
val body = response.body
128128
if(body == null) {
129129
return null
130-
}
131-
if (T::class.java == File::class.java) {
130+
} else if (T::class.java == Unit::class.java) {
131+
// No need to parse the body when we're not interested in the body
132+
// Useful when API is returning other Content-Type
133+
return null
134+
} else if (T::class.java == File::class.java) {
132135
// return tempFile
133136
val contentDisposition = response.header("Content-Disposition")
134137

samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
125125
val body = response.body
126126
if(body == null) {
127127
return null
128-
}
129-
if (T::class.java == File::class.java) {
128+
} else if (T::class.java == Unit::class.java) {
129+
// No need to parse the body when we're not interested in the body
130+
// Useful when API is returning other Content-Type
131+
return null
132+
} else if (T::class.java == File::class.java) {
130133
// return tempFile
131134
val contentDisposition = response.header("Content-Disposition")
132135

0 commit comments

Comments
 (0)