Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ captures
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings
node_modules/

# OpenAPI Generator metadata (generated each run, not needed in version control)
.openapi-generator/
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ plugins {
alias(libs.plugins.composeMultiplatform) apply false
alias(libs.plugins.composeCompiler) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.kotlinSerialization) apply false
alias(libs.plugins.openApiGenerator) apply false
}
19 changes: 19 additions & 0 deletions composeApp/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# OpenAPI Generator ignore file
# This file is used to exclude certain files from being overwritten during code generation.
# Files listed here will not be modified by `./gradlew generateFilcApiClient`.
# See: https://openapi-generator.tech/docs/customization/#ignore-file-format

# Gradle build files managed by this project
build.gradle.kts
settings.gradle.kts
gradle.properties
gradlew
gradlew.bat
gradle/

# Documentation managed by this project
README.md

# Android resources managed by this project
src/androidMain/
src/iosMain/
45 changes: 45 additions & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
// import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask

plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidApplication)
alias(libs.plugins.composeMultiplatform)
alias(libs.plugins.composeCompiler)
alias(libs.plugins.kotlinSerialization)
alias(libs.plugins.openApiGenerator)
}

// ---------------------------------------------------------------------------
// OpenAPI client generation
//
// Run `./gradlew generateFilcApiClient` to regenerate the API client
// whenever openapi/filc-openapi.json is updated. The generated sources are
// committed to version control so the project compiles without running the
// generator first.
// ---------------------------------------------------------------------------
val generateFilcApiClient by tasks.registering(GenerateTask::class) {
generatorName.set("kotlin")
library.set("multiplatform")
inputSpec.set(rootProject.file("openapi/filc-openapi.json").absolutePath)
outputDir.set(projectDir.absolutePath)
packageName.set("hu.petrik.filcapp.api")
apiPackage.set("hu.petrik.filcapp.api.client")
modelPackage.set("hu.petrik.filcapp.api.model")
configOptions.set(
mapOf(
"dateLibrary" to "string",
"serializationLibrary" to "kotlinx_serialization",
"omitGradleWrapper" to "true",
"omitGradlePluginVersions" to "true",
),
)
notCompatibleWithConfigurationCache("OpenAPI Generator Gradle plugin (org.openapi.generator) does not yet support Gradle configuration cache. See https://github.com/OpenAPITools/openapi-generator/issues/13113")
}

compose.resources {
Expand All @@ -31,6 +61,7 @@ kotlin {
androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.activity.compose)
implementation(libs.ktor.client.okhttp)
}
commonMain.dependencies {
implementation(compose.runtime)
Expand All @@ -47,6 +78,17 @@ kotlin {
implementation("cafe.adriel.voyager:voyager-navigator:1.0.0")
implementation("cafe.adriel.voyager:voyager-tab-navigator:1.0.0")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1")

// Ktor HTTP client (multiplatform)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.serialization.kotlinx.json)

// JSON serialization
implementation(libs.kotlinx.serialization.json)

// Coroutines
implementation(libs.kotlinx.coroutines.core)
}
commonTest.dependencies { implementation(libs.kotlin.test) }

Expand All @@ -58,6 +100,9 @@ kotlin {
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
dependencies {
implementation(libs.ktor.client.darwin)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package hu.petrik.filcapp.api.auth

class ApiKeyAuth(private val location: String, val paramName: String) : Authentication {
var apiKey: String? = null
var apiKeyPrefix: String? = null

override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
val key: String = apiKey ?: return
val prefix: String? = apiKeyPrefix
val value: String = if (prefix != null) "$prefix $key" else key
when (location) {
"query" -> query[paramName] = listOf(value)
"header" -> headers[paramName] = value
"cookie" -> {
val existing = headers["Cookie"]
headers["Cookie"] = if (existing != null) "$existing; $paramName=$value" else "$paramName=$value"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package hu.petrik.filcapp.api.auth

interface Authentication {

/**
* Apply authentication settings to header and query params.
*
* @param query Query parameters.
* @param headers Header parameters.
*/
fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package hu.petrik.filcapp.api.auth

import io.ktor.util.encodeBase64

class HttpBasicAuth : Authentication {
var username: String? = null
var password: String? = null

override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
if (username == null && password == null) return
val str = (username ?: "") + ":" + (password ?: "")
val auth = str.encodeBase64()
headers["Authorization"] = "Basic $auth"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hu.petrik.filcapp.api.auth

class HttpBearerAuth(private val scheme: String?) : Authentication {
var bearerToken: String? = null

override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
val token: String = bearerToken ?: return
headers["Authorization"] = (if (scheme != null) upperCaseBearer(scheme)!! + " " else "") + token
}

private fun upperCaseBearer(scheme: String): String? {
return if ("bearer".equals(scheme, ignoreCase = true)) "Bearer" else scheme
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package hu.petrik.filcapp.api.auth

class OAuth : Authentication {
var accessToken: String? = null

override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
val token: String = accessToken ?: return
headers["Authorization"] = "Bearer $token"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/

@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)

package hu.petrik.filcapp.api.client

import hu.petrik.filcapp.api.model.ErrorResponse
import hu.petrik.filcapp.api.model.GetCohortsForTimetable200Response

import hu.petrik.filcapp.api.infrastructure.*
import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
import io.ktor.client.request.forms.formData
import io.ktor.client.engine.HttpClientEngine
import kotlinx.serialization.json.Json
import io.ktor.http.ParametersBuilder
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*

open class CohortApi : ApiClient {

constructor(
baseUrl: String = ApiClient.BASE_URL,
httpClientEngine: HttpClientEngine? = null,
httpClientConfig: ((HttpClientConfig<*>) -> Unit)? = null,
jsonSerializer: Json = ApiClient.JSON_DEFAULT
) : super(baseUrl = baseUrl, httpClientEngine = httpClientEngine, httpClientConfig = httpClientConfig, jsonBlock = jsonSerializer)

constructor(
baseUrl: String,
httpClient: HttpClient
): super(baseUrl = baseUrl, httpClient = httpClient)

/**
* List all cohorts
*
* @return GetCohortsForTimetable200Response
*/
@Suppress("UNCHECKED_CAST")
open suspend fun getCohorts(): HttpResponse<GetCohortsForTimetable200Response> {

val localVariableAuthNames = listOf<String>("sessionAuth")

val localVariableBody =
io.ktor.client.utils.EmptyContent

val localVariableQuery = mutableMapOf<String, List<String>>()
val localVariableHeaders = mutableMapOf<String, String>()

val localVariableConfig = RequestConfig<kotlin.Any?>(
RequestMethod.GET,
"/cohort",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)

return request(
localVariableConfig,
localVariableBody,
localVariableAuthNames
).wrap()
}


}
Loading
Loading