@@ -92,8 +92,8 @@ case class ApiJsonServiceValidator(
9292 validateHeaders(form.headers),
9393 validateResources(form.resources),
9494 validateInterfaces(form.interfaces),
95- validateUnions(form.unions ),
96- validateModels(form.models ),
95+ validateUnions(form),
96+ validateModels(form),
9797 validateEnums(form.enums),
9898 validateAnnotations(form.annotations),
9999 DuplicateJsonParser .validateDuplicates(rawInput)
@@ -126,11 +126,13 @@ case class ApiJsonServiceValidator(
126126 )
127127 }
128128
129- private def validateUnions (unions : Seq [ InternalUnionForm ] ): ValidatedNec [String , Unit ] = {
129+ private def validateUnions (form : InternalApiJsonForm ): ValidatedNec [String , Unit ] = {
130130 sequenceUnique(
131- unions.map(_.warnings) ++ unions.map { union =>
132- validateAttributes(s " Union[ ${union.name}] " , union.attributes)
133- } ++ unions.map(validateUnionTypes)
131+ form.unions.map(_.warnings) ++ form.unions.map { union =>
132+ (validateAttributes(s " Union[ ${union.name}] " , union.attributes),
133+ validateTypeInterfaces(form, s " Union[ ${union.name}] " , union.interfaces)
134+ ).mapN { case (_, _) => () }
135+ } ++ form.unions.map(validateUnionTypes)
134136 )
135137 }
136138
@@ -180,14 +182,26 @@ case class ApiJsonServiceValidator(
180182 )
181183 }
182184
183- private def validateModels (models : Seq [ InternalModelForm ] ): ValidatedNec [String , Unit ] = {
185+ private def validateModels (form : InternalApiJsonForm ): ValidatedNec [String , Unit ] = {
184186 sequenceUnique(
185- models.map(_.warnings) ++ models.map { model =>
186- validateAttributes(s " Model[ ${model.name}] " , model.attributes)
187- } ++ Seq (validateFields(models))
187+ form.models.map(_.warnings) ++ form.models.map { model =>
188+ (validateAttributes(s " Model[ ${model.name}] " , model.attributes),
189+ validateTypeInterfaces(form, s " Model[ ${model.name}] " , model.interfaces)
190+ ).mapN { case (_, _) => () }
191+ } ++ Seq (validateFields(form.models))
188192 )
189193 }
190194
195+ private def validateTypeInterfaces (form : InternalApiJsonForm , name : String , interfaces : Seq [String ]): ValidatedNec [String , Unit ] = {
196+ interfaces.map { iName =>
197+ if (form.interfaces.exists(_.name == iName)) {
198+ ().validNec
199+ } else {
200+ s " $name cannot find interface named ' $iName' " .invalidNec
201+ }
202+ }.sequence.map { _ => () }
203+ }
204+
191205 private def validateHeaders (headers : Seq [InternalHeaderForm ]): ValidatedNec [String , Unit ] = {
192206 sequenceUnique(
193207 headers.map(_.warnings) ++ headers.filter(_.name.isDefined).map { header =>
0 commit comments