[kotlin] Change Kotlin client exceptions to expose lack of support as UnsupportedOperationException rather than NotImplementedException. (#3611)

* [kotlin] Throw catchable exceptions rather than TODO()

* [kotlin] Regenerate samples
This commit is contained in:
Jim Schubert 2019-08-13 08:38:00 -04:00 committed by GitHub
parent 93aedcf3d5
commit b936d72dfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 136 additions and 136 deletions

View File

@ -44,8 +44,8 @@ class {{classname}}(basePath: kotlin.String = "{{{basePath}}}") : ApiClient(base
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> {{#returnType}}(response as Success<*>).data as {{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}} ResponseType.Success -> {{#returnType}}(response as Success<*>).data as {{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@ -46,9 +46,9 @@ open class ApiClient(val baseUrl: String) {
mediaType == JsonMediaType -> Serializer.moshi.adapter(T::class.java).toJson(content).toRequestBody( mediaType == JsonMediaType -> Serializer.moshi.adapter(T::class.java).toJson(content).toRequestBody(
mediaType.toMediaTypeOrNull() mediaType.toMediaTypeOrNull()
) )
mediaType == XmlMediaType -> TODO("xml not currently supported.") mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.")
// TODO: this should be extended with other serializers // TODO: this should be extended with other serializers
else -> TODO("requestBody currently only supports JSON body and File body.") else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.")
} }
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
@ -61,7 +61,7 @@ open class ApiClient(val baseUrl: String) {
} }
return when(mediaType) { return when(mediaType) {
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
else -> TODO("responseBody currently only supports JSON body.") else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
} }
} }

View File

@ -51,8 +51,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -82,8 +82,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -113,8 +113,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet> ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet>
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -144,8 +144,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet> ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet>
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -175,8 +175,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Pet ResponseType.Success -> (response as Success<*>).data as Pet
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -205,8 +205,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -237,8 +237,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -270,8 +270,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as ApiResponse ResponseType.Success -> (response as Success<*>).data as ApiResponse
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@ -50,8 +50,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -80,8 +80,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int> ResponseType.Success -> (response as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int>
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -111,8 +111,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Order ResponseType.Success -> (response as Success<*>).data as Order
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -142,8 +142,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Order ResponseType.Success -> (response as Success<*>).data as Order
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@ -50,8 +50,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -80,8 +80,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -110,8 +110,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -140,8 +140,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -171,8 +171,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as User ResponseType.Success -> (response as Success<*>).data as User
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -203,8 +203,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.String ResponseType.Success -> (response as Success<*>).data as kotlin.String
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -232,8 +232,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -263,8 +263,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@ -46,9 +46,9 @@ open class ApiClient(val baseUrl: String) {
mediaType == JsonMediaType -> Serializer.moshi.adapter(T::class.java).toJson(content).toRequestBody( mediaType == JsonMediaType -> Serializer.moshi.adapter(T::class.java).toJson(content).toRequestBody(
mediaType.toMediaTypeOrNull() mediaType.toMediaTypeOrNull()
) )
mediaType == XmlMediaType -> TODO("xml not currently supported.") mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.")
// TODO: this should be extended with other serializers // TODO: this should be extended with other serializers
else -> TODO("requestBody currently only supports JSON body and File body.") else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.")
} }
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
@ -61,7 +61,7 @@ open class ApiClient(val baseUrl: String) {
} }
return when(mediaType) { return when(mediaType) {
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
else -> TODO("responseBody currently only supports JSON body.") else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
} }
} }

View File

@ -51,8 +51,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -82,8 +82,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -113,8 +113,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet> ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet>
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -144,8 +144,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet> ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet>
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -175,8 +175,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Pet ResponseType.Success -> (response as Success<*>).data as Pet
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -205,8 +205,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -237,8 +237,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -270,8 +270,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as ApiResponse ResponseType.Success -> (response as Success<*>).data as ApiResponse
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@ -50,8 +50,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -80,8 +80,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int> ResponseType.Success -> (response as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int>
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -111,8 +111,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Order ResponseType.Success -> (response as Success<*>).data as Order
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -142,8 +142,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Order ResponseType.Success -> (response as Success<*>).data as Order
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@ -50,8 +50,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -80,8 +80,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -110,8 +110,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -140,8 +140,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -171,8 +171,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as User ResponseType.Success -> (response as Success<*>).data as User
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -203,8 +203,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.String ResponseType.Success -> (response as Success<*>).data as kotlin.String
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -232,8 +232,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -263,8 +263,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@ -46,9 +46,9 @@ open class ApiClient(val baseUrl: String) {
mediaType == JsonMediaType -> Serializer.moshi.adapter(T::class.java).toJson(content).toRequestBody( mediaType == JsonMediaType -> Serializer.moshi.adapter(T::class.java).toJson(content).toRequestBody(
mediaType.toMediaTypeOrNull() mediaType.toMediaTypeOrNull()
) )
mediaType == XmlMediaType -> TODO("xml not currently supported.") mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.")
// TODO: this should be extended with other serializers // TODO: this should be extended with other serializers
else -> TODO("requestBody currently only supports JSON body and File body.") else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.")
} }
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
@ -61,7 +61,7 @@ open class ApiClient(val baseUrl: String) {
} }
return when(mediaType) { return when(mediaType) {
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
else -> TODO("responseBody currently only supports JSON body.") else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
} }
} }

View File

@ -40,8 +40,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational reponses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Rediration responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
else -> throw kotlin.IllegalStateException("Undefined ResponseType.") else -> throw kotlin.IllegalStateException("Undefined ResponseType.")

View File

@ -51,8 +51,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -82,8 +82,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -113,8 +113,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet> ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet>
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -144,8 +144,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet> ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet>
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -175,8 +175,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Pet ResponseType.Success -> (response as Success<*>).data as Pet
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -205,8 +205,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -237,8 +237,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -270,8 +270,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as ApiResponse ResponseType.Success -> (response as Success<*>).data as ApiResponse
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@ -50,8 +50,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -80,8 +80,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int> ResponseType.Success -> (response as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int>
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -111,8 +111,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Order ResponseType.Success -> (response as Success<*>).data as Order
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -142,8 +142,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Order ResponseType.Success -> (response as Success<*>).data as Order
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@ -50,8 +50,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -80,8 +80,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -110,8 +110,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -140,8 +140,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -171,8 +171,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as User ResponseType.Success -> (response as Success<*>).data as User
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -203,8 +203,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.String ResponseType.Success -> (response as Success<*>).data as kotlin.String
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -232,8 +232,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }
@ -263,8 +263,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
return when (response.responseType) { return when (response.responseType) {
ResponseType.Success -> Unit ResponseType.Success -> Unit
ResponseType.Informational -> TODO() ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> TODO() ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error") ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
} }

View File

@ -46,9 +46,9 @@ open class ApiClient(val baseUrl: String) {
mediaType == JsonMediaType -> Serializer.moshi.adapter(T::class.java).toJson(content).toRequestBody( mediaType == JsonMediaType -> Serializer.moshi.adapter(T::class.java).toJson(content).toRequestBody(
mediaType.toMediaTypeOrNull() mediaType.toMediaTypeOrNull()
) )
mediaType == XmlMediaType -> TODO("xml not currently supported.") mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.")
// TODO: this should be extended with other serializers // TODO: this should be extended with other serializers
else -> TODO("requestBody currently only supports JSON body and File body.") else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.")
} }
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
@ -61,7 +61,7 @@ open class ApiClient(val baseUrl: String) {
} }
return when(mediaType) { return when(mediaType) {
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent) JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
else -> TODO("responseBody currently only supports JSON body.") else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
} }
} }