aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiAbstractions.kt
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2021-12-03 21:49:03 -0600
committerIván Ávalos <avalos@disroot.org>2021-12-03 21:49:03 -0600
commit0a7f77b8cb2ed308c8f5e8cbf79d769bc3324c06 (patch)
treec308bb5b7ccb310cd57de815c93a7c200537d759 /shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiAbstractions.kt
parentc7039b6b0f6ab0f99fefecac07196ada6da2221a (diff)
downloadetbsa-trackermap-mobile-0a7f77b8cb2ed308c8f5e8cbf79d769bc3324c06.tar.gz
etbsa-trackermap-mobile-0a7f77b8cb2ed308c8f5e8cbf79d769bc3324c06.tar.bz2
etbsa-trackermap-mobile-0a7f77b8cb2ed308c8f5e8cbf79d769bc3324c06.zip
Added Swagger auto-generated API client (no Ktor yet)
Diffstat (limited to 'shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiAbstractions.kt')
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiAbstractions.kt20
1 files changed, 20 insertions, 0 deletions
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiAbstractions.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiAbstractions.kt
new file mode 100644
index 0000000..f63f301
--- /dev/null
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiAbstractions.kt
@@ -0,0 +1,20 @@
+package mx.trackermap.TrackerMap.client.infrastructure
+
+typealias MultiValueMap = Map<String, List<String>>
+
+fun collectionDelimiter(collectionFormat: String) = when (collectionFormat) {
+ "csv" -> ","
+ "tsv" -> "\t"
+ "pipes" -> "|"
+ "ssv" -> " "
+ else -> ""
+}
+
+val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" }
+
+fun <T : Any?> toMultiValue(items: List<T>, collectionFormat: String, map: (item: Any?) -> String = defaultMultiValueConverter): List<String> {
+ return when (collectionFormat) {
+ "multi" -> items.map(map)
+ else -> listOf(items.map(map).joinToString(separator = collectionDelimiter(collectionFormat)))
+ }
+} \ No newline at end of file