Skip to content

Commit c9d4a20

Browse files
feat(api): streamline public facing API
1 parent e2010ee commit c9d4a20

5 files changed

Lines changed: 25 additions & 11 deletions

File tree

codegen/src/main/kotlin/tools/samt/codegen/PublicApiMapper.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ class PublicApiMapper(
142142
else -> controller.reportGlobalError("Multiple transport configuration parsers found for transport '$name'")
143143
}
144144

145-
return object : TransportConfiguration {}
145+
return object : TransportConfiguration {
146+
override val name: String
147+
get() = this@toPublicTransport.name
148+
}
146149
}
147150

148151
private fun tools.samt.semantic.ProviderType.Implements.toPublicImplements() = object : ProvidedService {
@@ -169,7 +172,7 @@ class PublicApiMapper(
169172
override val name get() = this@toPublicAlias.name
170173
override val qualifiedName by unsafeLazy { this@toPublicAlias.getQualifiedName() }
171174
override val aliasedType by unsafeLazy { this@toPublicAlias.aliasedType.toPublicTypeReference() }
172-
override val fullyResolvedType by unsafeLazy { this@toPublicAlias.fullyResolvedType.toPublicTypeReference() }
175+
override val runtimeType by unsafeLazy { this@toPublicAlias.fullyResolvedType.toPublicTypeReference() }
173176
}
174177

175178
private inline fun <reified T : tools.samt.semantic.ResolvedTypeReference.Constraint> List<tools.samt.semantic.ResolvedTypeReference.Constraint>.findConstraint() =

codegen/src/main/kotlin/tools/samt/codegen/http/HttpTransport.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import tools.samt.api.transports.http.SerializationMode
99
import tools.samt.api.transports.http.TransportMode
1010

1111
object HttpTransportConfigurationParser : TransportConfigurationParser {
12-
override val transportName: String
13-
get() = "http"
12+
override val transportName: String get() = HttpTransportConfiguration.name
1413

1514
private val isValidRegex = Regex("""\w+\s+\S+(\s+\{.*?\s+in\s+\S+})*""")
1615
private val methodEndpointRegex = Regex("""(\w+)\s+(\S+)(.*)""")
@@ -212,6 +211,8 @@ class HttpTransportConfiguration(
212211
override val serializationMode: SerializationMode,
213212
val services: List<ServiceConfiguration>,
214213
) : SamtHttpTransport {
214+
override val name: String = HttpTransportConfiguration.name
215+
215216
class ServiceConfiguration(
216217
val name: String,
217218
val path: String,
@@ -284,4 +285,8 @@ class HttpTransportConfiguration(
284285
TransportMode.Body
285286
}
286287
}
288+
289+
companion object {
290+
const val name = "http"
291+
}
287292
}

codegen/src/main/kotlin/tools/samt/codegen/kotlin/ktor/KotlinKtorGeneratorUtilities.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,16 @@ private fun StringBuilder.appendDecodeRecordField(field: RecordField, options: M
121121
private fun StringBuilder.appendEncodeAlias(alias: AliasType, options: Map<String, String>) {
122122
appendLine("/** Encode alias ${alias.qualifiedName} to JSON */")
123123
appendLine("fun `encode ${alias.name}`(value: ${alias.getQualifiedName(options)}): JsonElement =")
124-
appendLine(" ${encodeJsonElement(alias.fullyResolvedType, options, valueName = "value")}")
124+
appendLine(" ${encodeJsonElement(alias.runtimeType, options, valueName = "value")}")
125125
}
126126

127127
private fun StringBuilder.appendDecodeAlias(alias: AliasType, options: Map<String, String>) {
128128
appendLine("/** Decode alias ${alias.qualifiedName} from JSON */")
129-
appendLine("fun `decode ${alias.name}`(json: JsonElement): ${alias.fullyResolvedType.getQualifiedName(options)} {")
130-
if (alias.fullyResolvedType.isRuntimeOptional) {
129+
appendLine("fun `decode ${alias.name}`(json: JsonElement): ${alias.runtimeType.getQualifiedName(options)} {")
130+
if (alias.runtimeType.isRuntimeOptional) {
131131
appendLine(" if (json is JsonNull) return null")
132132
}
133-
appendLine(" return ${decodeJsonElement(alias.fullyResolvedType, options, valueName = "json")}")
133+
appendLine(" return ${decodeJsonElement(alias.runtimeType, options, valueName = "json")}")
134134
appendLine("}")
135135
}
136136

public-api/src/main/kotlin/tools/samt/api/plugin/Transport.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ interface TransportConfigurationParser {
2626
* A base interface for transport configurations.
2727
* This interface is intended to be sub-typed and extended by transport configuration implementations.
2828
*/
29-
interface TransportConfiguration
29+
interface TransportConfiguration {
30+
/**
31+
* The name of this transport protocol.
32+
* Can be used to display to a user.
33+
*/
34+
val name: String
35+
}
3036

3137
/**
3238
* The parameters for a [TransportConfigurationParser].

public-api/src/main/kotlin/tools/samt/api/types/UserTypes.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ interface AliasType : UserType {
2020
val aliasedType: TypeReference
2121

2222
/**
23-
* The fully resolved type, will not contain any type aliases anymore, just the underlying merged type
23+
* The runtime type, which will not contain any type aliases, just the underlying merged type
2424
*/
25-
val fullyResolvedType: TypeReference
25+
val runtimeType: TypeReference
2626
}
2727

2828
/**

0 commit comments

Comments
 (0)