diff --git a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/requestData/GetPathsText.kt b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/requestData/GetPathsText.kt index 91852ea95..50105cf30 100644 --- a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/requestData/GetPathsText.kt +++ b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/requestData/GetPathsText.kt @@ -14,7 +14,7 @@ fun getPathsText(params: List): String { val pathPath = pathAnnotation?.value ?: "" val pathEncoded = pathAnnotation?.encoded ?: false - "${pathDataClass.name}(\"$pathPath\",$pathEncoded,\"\$$paramName\")" + "${pathDataClass.name}(\"$pathPath\",\"\$$paramName\",$pathEncoded)" }.joinToString { it }.surroundIfNotEmpty("paths = listOf(", ")") return pathData diff --git a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/PathAnnotationsTest.kt b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/PathAnnotationsTest.kt index 4506884f2..0304a0ef7 100644 --- a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/PathAnnotationsTest.kt +++ b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/PathAnnotationsTest.kt @@ -37,7 +37,7 @@ interface TestService { val requestData = RequestData(method="GET", relativeUrl="user/{id}", qualifiedRawTypeName="kotlin.String", - paths = listOf(PathData("id",false,"äid"))) + paths = listOf(PathData("id","äid",false))) return client.suspendRequest(requestData) }""".replace("\\{", "{").replace("ä","$") @@ -83,7 +83,7 @@ interface TestService { val requestData = RequestData(method="GET", relativeUrl="user/{id}", qualifiedRawTypeName="kotlin.String", - paths = listOf(PathData("id",true,"äid"))) + paths = listOf(PathData("id","äid",true))) return client.suspendRequest(requestData) }""".replace("%", "").replace("ä","$") diff --git a/ktorfit-lib/src/commonMain/kotlin/de/jensklingenberg/ktorfit/Ktorfit.kt b/ktorfit-lib/src/commonMain/kotlin/de/jensklingenberg/ktorfit/Ktorfit.kt index 85d6e46c3..1f2014cee 100644 --- a/ktorfit-lib/src/commonMain/kotlin/de/jensklingenberg/ktorfit/Ktorfit.kt +++ b/ktorfit-lib/src/commonMain/kotlin/de/jensklingenberg/ktorfit/Ktorfit.kt @@ -33,7 +33,7 @@ class Ktorfit private constructor( * @see httpClient */ class Builder { - private lateinit var _baseUrl: String + private var _baseUrl: String = "" private var _httpClient = HttpClient() private var _responseConverter: MutableSet = mutableSetOf() private var _suspendResponseConverter: MutableSet = mutableSetOf() @@ -42,6 +42,13 @@ class Ktorfit private constructor( * That will be used for every request with object */ fun baseUrl(url: String) = apply { + if (url.isEmpty()) { + throw IllegalStateException("Base URL required") + } + + if (!url.endsWith("/")) { + throw IllegalStateException("Base URL needs to end with /") + } this._baseUrl = url } @@ -96,14 +103,6 @@ class Ktorfit private constructor( * Creates an instance of Ktorfit with specified baseUrl and HttpClient. */ fun build(): Ktorfit { - if (!this::_baseUrl.isInitialized || this._baseUrl.isEmpty()) { - throw IllegalStateException("Base URL required") - } - - if (!_baseUrl.endsWith("/")) { - throw IllegalStateException("Base URL needs to end with /") - } - return Ktorfit(_baseUrl, _httpClient, _responseConverter, _suspendResponseConverter) } }