@@ -24,31 +24,53 @@ class AsyncApi {
2424 fun id (value : String ): String =
2525 value.also { id = it }
2626
27- inline fun info (build : Info .() -> Unit ): Info =
27+ fun info (build : Info .() -> Unit ): Info =
2828 Info ().apply (build).also { info = it }
2929
30- inline fun servers (build : ReferencableServersMap .() -> Unit ): ReferencableServersMap =
30+ fun servers (build : ReferencableServersMap .() -> Unit ): ReferencableServersMap =
3131 ReferencableServersMap ().apply (build).also { servers = it }
3232
33- inline fun channels (build : ReferencableChannelsMap .() -> Unit ): ReferencableChannelsMap =
33+ fun channels (build : ReferencableChannelsMap .() -> Unit ): ReferencableChannelsMap =
3434 ReferencableChannelsMap ().apply (build).also { channels = it }
3535
3636 fun defaultContentType (value : String ): String =
3737 value.also { defaultContentType = it }
3838
39- inline fun components (build : Components .() -> Unit ): Components =
39+ fun components (build : Components .() -> Unit ): Components =
4040 Components ().apply (build).also { components = it }
4141
42- inline fun tags (build : TagsList .() -> Unit ): TagsList =
42+ fun tags (build : TagsList .() -> Unit ): TagsList =
4343 TagsList ().apply (build).also { tags = it }
4444
45- inline fun externalDocs (build : ExternalDocumentation .() -> Unit ): ExternalDocumentation =
45+ fun externalDocs (build : ExternalDocumentation .() -> Unit ): ExternalDocumentation =
4646 ExternalDocumentation ().apply (build).also { externalDocs = it }
4747
4848 companion object {
4949 const val VERSION = " 2.4.0"
5050
51- inline fun asyncApi (build : AsyncApi .() -> Unit ): AsyncApi =
52- AsyncApi ().apply (build)
51+ fun asyncApi (build : AsyncApi .() -> Unit ): AsyncApi =
52+ AsyncApi ()
53+ .apply (build)
54+ .checkInitialized(
55+ " info" to { info },
56+ " channels" to { channels }
57+ )
58+ }
59+ }
60+
61+ fun <T > T.checkInitialized (
62+ vararg checks : Pair <String , T .() - > Unit >
63+ ): T = also {
64+ val missing = checks.mapNotNull { (name, check) ->
65+ try {
66+ it.check()
67+ null
68+ } catch (_: UninitializedPropertyAccessException ) {
69+ name
70+ }
71+ }
72+
73+ check(missing.isEmpty()) {
74+ " Missing required properties: ${missing.joinToString()} "
5375 }
5476}
0 commit comments