Skip to content
This repository was archived by the owner on Nov 6, 2019. It is now read-only.

Commit a2d2266

Browse files
committed
Handle union of string values
1 parent 8ccb3c6 commit a2d2266

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/main/kotlin/converter/typeUtils.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,19 @@ private fun ObjectTypeToKotlinTypeMapper.mapUnionType(type: UnionOrIntersectionT
115115

116116
val mappedTypes = notNullTypes.map { mapType(it, null) }
117117
return KtTypeUnion(when {
118-
!nullable -> mappedTypes.distinct()
118+
!nullable -> mappedTypes.merge()
119119
notNullTypes.size == 1 -> mappedTypes.map { it.copy(isNullable = true) }
120120
else -> (mappedTypes + KtType(NOTHING, isNullable = true)).distinct()
121121
})
122122
}
123123

124+
private fun List<KtType>.merge(): List<KtType> {
125+
return groupBy { it.copy(comment = null) }.map { entry ->
126+
val comments = entry.value.map { it.comment }.filterNotNull()
127+
entry.key.copy(comment = if (comments.isEmpty()) null else comments.joinToString(" | "))
128+
}
129+
}
130+
124131
private inline val UnionOrIntersectionType.containsUndefined: Boolean
125132
get() {
126133
val array = types.asDynamic()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package stringValues
2+
3+
external interface MapGenerator {
4+
fun generate(scope: String /* "city" | "state" | "country" | "world" */)
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type GeographicScope = 'city' | 'state' | 'country' | 'world';
2+
3+
export interface MapGenerator {
4+
generate(scope: GeographicScope)
5+
}

0 commit comments

Comments
 (0)