@@ -55,14 +55,16 @@ class PublicApiMapper(
5555 override val name = this @toPublicRequestResponseOperation.name
5656 override val parameters = this @toPublicRequestResponseOperation.parameters.map { it.toPublicParameter() }
5757 override val returnType = this @toPublicRequestResponseOperation.returnType?.toPublicTypeReference()
58- override val raisesTypes = this @toPublicRequestResponseOperation.raisesTypes.map { it.toPublicTypeReference() }
58+ override val raisesTypes =
59+ this @toPublicRequestResponseOperation.raisesTypes.map { it.toPublicTypeReference() }
5960 override val isAsync = this @toPublicRequestResponseOperation.isAsync
6061 }
6162
62- private fun tools.samt.semantic.ServiceType.Operation.Parameter.toPublicParameter () = object : ServiceOperationParameter {
63- override val name = this @toPublicParameter.name
64- override val type = this @toPublicParameter.type.toPublicTypeReference()
65- }
63+ private fun tools.samt.semantic.ServiceType.Operation.Parameter.toPublicParameter () =
64+ object : ServiceOperationParameter {
65+ override val name = this @toPublicParameter.name
66+ override val type = this @toPublicParameter.type.toPublicTypeReference()
67+ }
6668
6769 private fun tools.samt.semantic.ProviderType.toPublicProvider () = object : ProviderType {
6870 override val name = this @toPublicProvider.name
@@ -108,6 +110,7 @@ class PublicApiMapper(
108110 return transportConfigurationParser.default()
109111 }
110112 }
113+
111114 else -> controller.reportGlobalError(" Multiple transport configuration parsers found for transport '$name '" )
112115 }
113116
@@ -142,20 +145,40 @@ class PublicApiMapper(
142145
143146 private fun tools.samt.semantic.TypeReference?.toPublicTypeReference (): TypeReference {
144147 check(this is tools.samt.semantic.ResolvedTypeReference )
148+ val typeReference = this @toPublicTypeReference
149+ val runtimeTypeReference = when (val type = typeReference.type) {
150+ is tools.samt.semantic.AliasType -> checkNotNull(type.fullyResolvedType) { " Found unresolved alias when generating code" }
151+ else -> typeReference
152+ }
145153 return object : TypeReference {
146- override val type = this @toPublicTypeReference .type.toPublicType()
147- override val isOptional = this @toPublicTypeReference .isOptional
154+ override val type = typeReference .type.toPublicType()
155+ override val isOptional = typeReference .isOptional
148156 override val rangeConstraint =
149- this @toPublicTypeReference .constraints.findConstraint< tools.samt.semantic.ResolvedTypeReference .Constraint .Range > ()
157+ typeReference .constraints.findConstraint< tools.samt.semantic.ResolvedTypeReference .Constraint .Range > ()
150158 ?.toPublicRangeConstraint()
151159 override val sizeConstraint =
152- this @toPublicTypeReference .constraints.findConstraint< tools.samt.semantic.ResolvedTypeReference .Constraint .Size > ()
160+ typeReference .constraints.findConstraint< tools.samt.semantic.ResolvedTypeReference .Constraint .Size > ()
153161 ?.toPublicSizeConstraint()
154162 override val patternConstraint =
155- this @toPublicTypeReference .constraints.findConstraint< tools.samt.semantic.ResolvedTypeReference .Constraint .Pattern > ()
163+ typeReference .constraints.findConstraint< tools.samt.semantic.ResolvedTypeReference .Constraint .Pattern > ()
156164 ?.toPublicPatternConstraint()
157165 override val valueConstraint =
158- this @toPublicTypeReference.constraints.findConstraint< tools.samt.semantic.ResolvedTypeReference .Constraint .Value > ()
166+ typeReference.constraints.findConstraint< tools.samt.semantic.ResolvedTypeReference .Constraint .Value > ()
167+ ?.toPublicValueConstraint()
168+
169+ override val runtimeType = runtimeTypeReference.type.toPublicType()
170+ override val isRuntimeOptional = isOptional || runtimeTypeReference.isOptional
171+ override val runtimeRangeConstraint = rangeConstraint
172+ ? : runtimeTypeReference.constraints.findConstraint< tools.samt.semantic.ResolvedTypeReference .Constraint .Range > ()
173+ ?.toPublicRangeConstraint()
174+ override val runtimeSizeConstraint = sizeConstraint
175+ ? : runtimeTypeReference.constraints.findConstraint< tools.samt.semantic.ResolvedTypeReference .Constraint .Size > ()
176+ ?.toPublicSizeConstraint()
177+ override val runtimePatternConstraint = patternConstraint
178+ ? : runtimeTypeReference.constraints.findConstraint< tools.samt.semantic.ResolvedTypeReference .Constraint .Pattern > ()
179+ ?.toPublicPatternConstraint()
180+ override val runtimeValueConstraint = valueConstraint
181+ ? : runtimeTypeReference.constraints.findConstraint< tools.samt.semantic.ResolvedTypeReference .Constraint .Value > ()
159182 ?.toPublicValueConstraint()
160183 }
161184 }
@@ -191,24 +214,27 @@ class PublicApiMapper(
191214 tools.samt.semantic.UnknownType -> error(" Unknown type cannot be converted to public API" )
192215 }
193216
194- private fun tools.samt.semantic.ResolvedTypeReference.Constraint.Range.toPublicRangeConstraint () = object : Constraint .Range {
195- override val lowerBound = this @toPublicRangeConstraint.lowerBound
196- override val upperBound = this @toPublicRangeConstraint.upperBound
197- }
217+ private fun tools.samt.semantic.ResolvedTypeReference.Constraint.Range.toPublicRangeConstraint () =
218+ object : Constraint .Range {
219+ override val lowerBound = this @toPublicRangeConstraint.lowerBound
220+ override val upperBound = this @toPublicRangeConstraint.upperBound
221+ }
198222
199- private fun tools.samt.semantic.ResolvedTypeReference.Constraint.Size.toPublicSizeConstraint () = object : Constraint .Size {
200- override val lowerBound = this @toPublicSizeConstraint.lowerBound
201- override val upperBound = this @toPublicSizeConstraint.upperBound
202- }
223+ private fun tools.samt.semantic.ResolvedTypeReference.Constraint.Size.toPublicSizeConstraint () =
224+ object : Constraint .Size {
225+ override val lowerBound = this @toPublicSizeConstraint.lowerBound
226+ override val upperBound = this @toPublicSizeConstraint.upperBound
227+ }
203228
204229 private fun tools.samt.semantic.ResolvedTypeReference.Constraint.Pattern.toPublicPatternConstraint () =
205230 object : Constraint .Pattern {
206231 override val pattern = this @toPublicPatternConstraint.pattern
207232 }
208233
209- private fun tools.samt.semantic.ResolvedTypeReference.Constraint.Value.toPublicValueConstraint () = object : Constraint .Value {
210- override val value = this @toPublicValueConstraint.value
211- }
234+ private fun tools.samt.semantic.ResolvedTypeReference.Constraint.Value.toPublicValueConstraint () =
235+ object : Constraint .Value {
236+ override val value = this @toPublicValueConstraint.value
237+ }
212238
213239 private fun tools.samt.semantic.UserDeclaredNamedType.getQualifiedName (): String {
214240 val components = parentPackage.nameComponents + name
0 commit comments