@@ -5,24 +5,33 @@ import tools.samt.api.plugin.Generator
55import tools.samt.api.plugin.GeneratorParams
66import tools.samt.api.plugin.TransportConfigurationParser
77import tools.samt.api.types.SamtPackage
8- import tools.samt.codegen.http.HttpTransportConfigurationParser
9- import tools.samt.codegen.kotlin.KotlinTypesGenerator
10- import tools.samt.codegen.kotlin.ktor.KotlinKtorConsumerGenerator
11- import tools.samt.codegen.kotlin.ktor.KotlinKtorProviderGenerator
128import tools.samt.common.DiagnosticController
139import tools.samt.common.SamtGeneratorConfiguration
1410import tools.samt.semantic.SemanticModel
1511
1612object Codegen {
17- private val generators: List <Generator > = listOf (
18- KotlinTypesGenerator ,
19- KotlinKtorProviderGenerator ,
20- KotlinKtorConsumerGenerator ,
21- )
13+ private val generators: MutableList <Generator > = mutableListOf ()
2214
23- private val transports: List <TransportConfigurationParser > = listOf (
24- HttpTransportConfigurationParser ,
25- )
15+ /* *
16+ * Register the [generator] to be used when generating code.
17+ * The generator is called when a user configures it within their `samt.yaml` configuration, where the generator is referenced by its [Generator.name].
18+ * Only generators registered here will be considered when calling [generate].
19+ */
20+ @JvmStatic
21+ fun registerGenerator (generator : Generator ) {
22+ generators + = generator
23+ }
24+
25+ private val transports: MutableList <TransportConfigurationParser > = mutableListOf ()
26+
27+ /* *
28+ * Register the [parser] as a transport configuration, which will be used to parse the `transport` section of a SAMT provider.
29+ * Only transport configurations registered here will be considered when calling [generate].
30+ */
31+ @JvmStatic
32+ fun registerTransportParser (parser : TransportConfigurationParser ) {
33+ transports + = parser
34+ }
2635
2736 internal class SamtGeneratorParams (
2837 semanticModel : SemanticModel ,
@@ -45,6 +54,12 @@ object Codegen {
4554 }
4655 }
4756
57+ /* *
58+ * Run the appropriate generator for the given [configuration], using the given [semanticModel].
59+ * To ensure binary compatibility, the types within the [semanticModel] will be mapped to their [tools.samt.api] equivalents.
60+ * @return a list of generated files
61+ */
62+ @JvmStatic
4863 fun generate (
4964 semanticModel : SemanticModel ,
5065 configuration : SamtGeneratorConfiguration ,
0 commit comments