Skip to content

Commit

Permalink
Requests with JSON bodies weren't working without this fix. Probably …
Browse files Browse the repository at this point in the history
…an issue in the Kotlin generator?
  • Loading branch information
dvankley committed Sep 25, 2022
1 parent b6abc1a commit d1de0d4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.serialization.jackson.*
import net.djvk.fireflyPlaidConnector2.api.firefly.auth.*
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component

abstract class ApiClient(
private val baseUrl: String,
Expand Down Expand Up @@ -56,7 +54,7 @@ abstract class ApiClient(
})
registerModule(JavaTimeModule())
}
protected val UNSAFE_HEADERS = listOf(HttpHeaders.ContentType)
protected val UNSAFE_HEADERS = listOf<String>()
}

/**
Expand Down Expand Up @@ -149,7 +147,10 @@ abstract class ApiClient(
requestConfig: RequestConfig<T>,
body: Any? = null,
authNames: List<String>
): HttpResponse = request(requestConfig, body, authNames)
): HttpResponse {
requestConfig.headers[HttpHeaders.ContentType] = ContentType.Application.Json.toString()
return request(requestConfig, body, authNames)
}

protected suspend fun <T : Any?> request(
requestConfig: RequestConfig<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ import io.ktor.client.*
import io.ktor.client.engine.*
import net.djvk.fireflyPlaidConnector2.api.plaid.infrastructure.*
import net.djvk.fireflyPlaidConnector2.api.plaid.models.*
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component
import java.io.File

@Component
open class PlaidApi(
@Value("\${fireflyPlaidConnector2.plaid.url}")
baseUrl: String = ApiClient.BASE_URL,
httpClientEngine: HttpClientEngine? = null,
httpClientConfig: ((HttpClientConfig<*>) -> Unit)? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import io.ktor.http.content.*
import io.ktor.serialization.jackson.*
import net.djvk.fireflyPlaidConnector2.api.plaid.auth.*

const val clientIdHeader = "PLAID-CLIENT-ID"
const val secretHeader = "PLAID-SECRET"

open class ApiClient(
private val baseUrl: String,
httpClientEngine: HttpClientEngine?,
Expand All @@ -39,9 +42,9 @@ open class ApiClient(

private val authentications: Map<String, Authentication> by lazy {
mapOf(
"clientId" to ApiKeyAuth("header", "PLAID-CLIENT-ID"),
"clientId" to ApiKeyAuth("header", clientIdHeader),
"plaidVersion" to ApiKeyAuth("header", "Plaid-Version"),
"secret" to ApiKeyAuth("header", "PLAID-SECRET")
"secret" to ApiKeyAuth("header", secretHeader)
)
}

Expand All @@ -55,7 +58,7 @@ open class ApiClient(
})
registerModule(JavaTimeModule())
}
protected val UNSAFE_HEADERS = listOf(HttpHeaders.ContentType)
protected val UNSAFE_HEADERS = listOf<String>()
}

/**
Expand Down Expand Up @@ -148,7 +151,10 @@ open class ApiClient(
requestConfig: RequestConfig<T>,
body: Any? = null,
authNames: List<String>
): HttpResponse = request(requestConfig, body, authNames)
): HttpResponse {
requestConfig.headers[HttpHeaders.ContentType] = ContentType.Application.Json.toString()
return request(requestConfig, body, authNames)
}

protected suspend fun <T : Any?> request(
requestConfig: RequestConfig<T>,
Expand Down

0 comments on commit d1de0d4

Please sign in to comment.