@@ -38,10 +38,9 @@ final case class Resolver[F[_]](repos: List[Registry], cache: Option[ResolverCac
38
38
private [client] val allRepos : NonEmptyList [Registry ] =
39
39
NonEmptyList [Registry ](Registry .EmbeddedRegistry , repos)
40
40
41
- private val allIgluCentral = repos.collect {
41
+ private val allIgluCentral : Set [ String ] = repos.collect {
42
42
case Registry .Http (config, connection)
43
- if config.name.toLowerCase.matches(" .*iglu[- ]?central.*" ) && connection.uri.toString
44
- .contains(" iglucentral" ) =>
43
+ if Option (connection).filter(_.uri.getHost.matches(""" .*\biglucentral\b.*""" )).isDefined =>
45
44
config.name
46
45
}.toSet
47
46
@@ -188,30 +187,38 @@ final case class Resolver[F[_]](repos: List[Registry], cache: Option[ResolverCac
188
187
): F [Either [ResolutionError , Json ]] =
189
188
lookupSchemaResult(schemaKey).map(_.map(_.value.schema))
190
189
190
+ /**
191
+ * Looks up all the schemas with the same model until `maxSchemaKey`.
192
+ * For the schemas of previous revisions, it starts with addition = 0
193
+ * and increments it until a NotFound.
194
+ *
195
+ * @param maxSchemaKey The SchemaKey until which schemas of the same model should get returned
196
+ * @return All the schemas if all went well, [[Resolver.SchemaResolutionError ]] with the first error that happened
197
+ * while looking up the schemas if something went wrong.
198
+ */
191
199
def lookupSchemasUntil (
192
200
maxSchemaKey : SchemaKey
193
201
)(implicit
194
202
F : Monad [F ],
195
203
L : RegistryLookup [F ],
196
204
C : Clock [F ]
197
- ): F [Either [SchemaResolutionError , List [RawSchema ]]] = {
205
+ ): F [Either [SchemaResolutionError , List [SelfDescribingSchema [ Json ] ]]] = {
198
206
199
207
// If Iglu Central or any of its mirrors doesn't have a schema,
200
208
// it should be considered NotFound, even if one of them returned an error
201
209
def isNotFound (error : ResolutionError ): Boolean = {
202
210
val (igluCentral, custom) = error.value.partition { case (repo, _) =>
203
211
allIgluCentral.contains(repo)
204
212
}
205
- custom.values.flatMap(_.errors).forall(_ == RegistryError .NotFound ) &&
206
213
(igluCentral.isEmpty || igluCentral.values.exists(
207
214
_.errors.forall(_ == RegistryError .NotFound )
208
- ))
215
+ )) && custom.values.flatMap(_.errors).forall(_ == RegistryError . NotFound )
209
216
}
210
217
211
218
def go (
212
219
current : SchemaVer .Full ,
213
- acc : List [RawSchema ]
214
- ): F [Either [SchemaResolutionError , List [RawSchema ]]] = {
220
+ acc : List [SelfDescribingSchema [ Json ] ]
221
+ ): F [Either [SchemaResolutionError , List [SelfDescribingSchema [ Json ] ]]] = {
215
222
val currentSchemaKey = maxSchemaKey.copy(version = current)
216
223
lookupSchema(currentSchemaKey).flatMap {
217
224
case Left (e) =>
@@ -225,15 +232,17 @@ final case class Resolver[F[_]](repos: List[Registry], cache: Option[ResolverCac
225
232
if (current.revision < maxSchemaKey.version.revision)
226
233
go(
227
234
current.copy(addition = current.addition + 1 ),
228
- RawSchema ( currentSchemaKey, json) :: acc
235
+ SelfDescribingSchema ( SchemaMap ( currentSchemaKey) , json) :: acc
229
236
)
230
237
else if (current.addition < maxSchemaKey.version.addition)
231
238
go(
232
239
current.copy(addition = current.addition + 1 ),
233
- RawSchema ( currentSchemaKey, json) :: acc
240
+ SelfDescribingSchema ( SchemaMap ( currentSchemaKey) , json) :: acc
234
241
)
235
242
else
236
- Monad [F ].pure(Right ((RawSchema (currentSchemaKey, json) :: acc).reverse))
243
+ Monad [F ].pure(
244
+ Right ((SelfDescribingSchema (SchemaMap (currentSchemaKey), json) :: acc).reverse)
245
+ )
237
246
}
238
247
}
239
248
@@ -439,8 +448,6 @@ object Resolver {
439
448
type SchemaListLookupResult = ResolverResult [SchemaListKey , SchemaList ]
440
449
type SupersededBy = Option [SchemaVer .Full ]
441
450
442
- case class RawSchema (schemaKey : SchemaKey , json : Json )
443
-
444
451
/**
445
452
* The result of doing schema lookup
446
453
*
0 commit comments