Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[kotlin] update pet projects
  • Loading branch information
4brunu committed Oct 9, 2019
commit fecc4162708620ed372dd1a5a84f7fbd155b136c
2 changes: 1 addition & 1 deletion samples/client/petstore/kotlin-nonpublic/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ dependencies {
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "com.squareup.moshi:moshi-kotlin:1.8.0"
compile "com.squareup.moshi:moshi-adapters:1.8.0"
compile "com.squareup.okhttp3:okhttp:4.0.1"
compile "com.squareup.okhttp3:okhttp:4.2.0"
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.1.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ internal val Response.isClientError : Boolean get() = this.code in 400..499
/**
* Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code
*/
internal val Response.isServerError : Boolean get() = this.code in 500..999
internal val Response.isServerError : Boolean get() = this.code in 500..999
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.3-SNAPSHOT
4.2.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
public class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {

/**
* Add a new pet to the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
public class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {

/**
* Delete purchase order by ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.openapitools.client.infrastructure.ResponseType
import org.openapitools.client.infrastructure.Success
import org.openapitools.client.infrastructure.toMultiValue

class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
public class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {

/**
* Create user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package org.openapitools.client.infrastructure

typealias MultiValueMap = Map<String,List<String>>

fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) {
public fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) {
"csv" -> ","
"tsv" -> "\t"
"pipes" -> "|"
"ssv" -> " "
else -> ""
}

val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" }
public val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" }

fun <T : Any?> toMultiValue(items: Array<T>, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter)
public fun <T : Any?> toMultiValue(items: Array<T>, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter)
= toMultiValue(items.asIterable(), collectionFormat, map)

fun <T : Any?> toMultiValue(items: Iterable<T>, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter): List<String> {
public fun <T : Any?> toMultiValue(items: Iterable<T>, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter): List<String> {
return when(collectionFormat) {
"multi" -> items.map(map)
else -> listOf(items.joinToString(separator = collectionDelimiter(collectionFormat), transform = map))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import okhttp3.ResponseBody
import okhttp3.Request
import java.io.File

open class ApiClient(val baseUrl: String) {
companion object {
public open class ApiClient(val baseUrl: String) {
public companion object {
protected const val ContentType = "Content-Type"
protected const val Accept = "Accept"
protected const val Authorization = "Authorization"
Expand Down Expand Up @@ -122,7 +122,7 @@ open class ApiClient(val baseUrl: String) {
val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase()

val request = when (requestConfig.method) {
RequestMethod.DELETE -> Request.Builder().url(url).delete()
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType))
RequestMethod.GET -> Request.Builder().url(url)
RequestMethod.HEAD -> Request.Builder().url(url).head()
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body, contentType))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package org.openapitools.client.infrastructure

enum class ResponseType {
public enum class ResponseType {
Success, Informational, Redirection, ClientError, ServerError
}

abstract class ApiInfrastructureResponse<T>(val responseType: ResponseType) {
public abstract class ApiInfrastructureResponse<T>(val responseType: ResponseType) {
abstract val statusCode: Int
abstract val headers: Map<String,List<String>>
}

class Success<T>(
public class Success<T>(
val data: T,
override val statusCode: Int = -1,
override val headers: Map<String, List<String>> = mapOf()
): ApiInfrastructureResponse<T>(ResponseType.Success)

class Informational<T>(
public class Informational<T>(
val statusText: String,
override val statusCode: Int = -1,
override val headers: Map<String, List<String>> = mapOf()
) : ApiInfrastructureResponse<T>(ResponseType.Informational)

class Redirection<T>(
public class Redirection<T>(
override val statusCode: Int = -1,
override val headers: Map<String, List<String>> = mapOf()
) : ApiInfrastructureResponse<T>(ResponseType.Redirection)

class ClientError<T>(
public class ClientError<T>(
val body: Any? = null,
override val statusCode: Int = -1,
override val headers: Map<String, List<String>> = mapOf()
) : ApiInfrastructureResponse<T>(ResponseType.ClientError)

class ServerError<T>(
public class ServerError<T>(
val message: String? = null,
val body: Any? = null,
override val statusCode: Int = -1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.openapitools.client.infrastructure
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

object ApplicationDelegates {
public object ApplicationDelegates {
/**
* Provides a property delegate, allowing the property to be set once and only once.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.openapitools.client.infrastructure
import com.squareup.moshi.FromJson
import com.squareup.moshi.ToJson

class ByteArrayAdapter {
public class ByteArrayAdapter {
@ToJson
fun toJson(data: ByteArray): String = String(data)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.openapitools.client.infrastructure

import java.lang.RuntimeException

open class ClientException : RuntimeException {
public open class ClientException : RuntimeException {

/**
* Constructs an [ClientException] with no detail message.
Expand All @@ -22,7 +22,7 @@ open class ClientException : RuntimeException {
}
}

open class ServerException : RuntimeException {
public open class ServerException : RuntimeException {

/**
* Constructs an [ServerException] with no detail message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.squareup.moshi.ToJson
import java.time.LocalDate
import java.time.format.DateTimeFormatter

class LocalDateAdapter {
public class LocalDateAdapter {
@ToJson
fun toJson(value: LocalDate): String {
return DateTimeFormatter.ISO_LOCAL_DATE.format(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.squareup.moshi.ToJson
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

class LocalDateTimeAdapter {
public class LocalDateTimeAdapter {
@ToJson
fun toJson(value: LocalDateTime): String {
return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package org.openapitools.client.infrastructure
* NOTE: Headers is a Map<String,String> because rfc2616 defines
* multi-valued headers as csv-only.
*/
data class RequestConfig(
public data class RequestConfig(
val method: RequestMethod,
val path: String,
val headers: MutableMap<String, String> = mutableMapOf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package org.openapitools.client.infrastructure
/**
* Provides enumerated HTTP verbs
*/
enum class RequestMethod {
public enum class RequestMethod {
GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import okhttp3.Response
/**
* Provides an extension to evaluation whether the response is a 1xx code
*/
val Response.isInformational : Boolean get() = this.code() in 100..199
public val Response.isInformational : Boolean get() = this.code() in 100..199

/**
* Provides an extension to evaluation whether the response is a 3xx code
*/
val Response.isRedirect : Boolean get() = this.code() in 300..399
public val Response.isRedirect : Boolean get() = this.code() in 300..399

/**
* Provides an extension to evaluation whether the response is a 4xx code
*/
val Response.isClientError : Boolean get() = this.code() in 400..499
public val Response.isClientError : Boolean get() = this.code() in 400..499

/**
* Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code
*/
val Response.isServerError : Boolean get() = this.code() in 500..999
public val Response.isServerError : Boolean get() = this.code() in 500..999
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import java.util.Date

object Serializer {
public object Serializer {
@JvmStatic
val moshi: Moshi = Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.squareup.moshi.FromJson
import com.squareup.moshi.ToJson
import java.util.UUID

class UUIDAdapter {
public class UUIDAdapter {
@ToJson
fun toJson(uuid: UUID) = uuid.toString()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ import kotlinx.android.parcel.Parcelize
*/
@Parcelize

data class ApiResponse (
public data class ApiResponse (
@Json(name = "code")
val code: kotlin.Int? = null,
@Json(name = "type")
val type: kotlin.String? = null,
@Json(name = "message")
val message: kotlin.String? = null
) : Parcelable
) : Parcelable





Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ import kotlinx.android.parcel.Parcelize
*/
@Parcelize

data class Category (
public data class Category (
@Json(name = "id")
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
) : Parcelable
) : Parcelable





Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import kotlinx.android.parcel.Parcelize
*/
@Parcelize

data class Order (
public data class Order (
@Json(name = "id")
val id: kotlin.Long? = null,
@Json(name = "petId")
Expand All @@ -41,15 +41,18 @@ data class Order (
val status: Order.Status? = null,
@Json(name = "complete")
val complete: kotlin.Boolean? = null
) : Parcelable
{
) : Parcelable





/**
* Order Status
* Values: placed,approved,delivered
*/

enum class Status(val value: kotlin.String){
public enum class Status(val value: kotlin.String){

@Json(name = "placed") placed("placed"),

Expand All @@ -60,5 +63,5 @@ data class Order (

}

}


Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import kotlinx.android.parcel.Parcelize
*/
@Parcelize

data class Pet (
public data class Pet (
@Json(name = "name")
val name: kotlin.String,
@Json(name = "photoUrls")
Expand All @@ -43,15 +43,18 @@ data class Pet (
/* pet status in the store */
@Json(name = "status")
val status: Pet.Status? = null
) : Parcelable
{
) : Parcelable





/**
* pet status in the store
* Values: available,pending,sold
*/

enum class Status(val value: kotlin.String){
public enum class Status(val value: kotlin.String){

@Json(name = "available") available("available"),

Expand All @@ -62,5 +65,5 @@ data class Pet (

}

}


Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ import kotlinx.android.parcel.Parcelize
*/
@Parcelize

data class Tag (
public data class Tag (
@Json(name = "id")
val id: kotlin.Long? = null,
@Json(name = "name")
val name: kotlin.String? = null
) : Parcelable
) : Parcelable





Loading