-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathAvroSchemaParser.kt
32 lines (28 loc) · 1019 Bytes
/
AvroSchemaParser.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.github.imflog.schema.registry.parser
import com.github.imflog.schema.registry.LocalReference
import com.github.imflog.schema.registry.SchemaType
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
import com.github.imflog.avro.Schema.Parser
import java.io.File
class AvroSchemaParser(
client: SchemaRegistryClient,
rootDir: File
) : SchemaParser(client, rootDir) {
override val schemaType: SchemaType = SchemaType.AVRO
override fun resolveLocalReferences(
subject: String,
schemaPath: String,
localReferences: List<LocalReference>
): String {
val parser = Parser()
.setValidate(false)
.setValidateDefaults(false)
.setValidateUnknownTypes(false)
localReferences
.reversed()
.map { reference -> reference.content(rootDir) }
.forEach { parser.parse(it) }
val content = loadContent(schemaPath)
return parser.parse(content).toString()
}
}