-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from driessamyn/schema-endpoint
Schema registry endpoints
- Loading branch information
Showing
12 changed files
with
159 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
http/serialisation/avro/src/main/kotlin/kafkasnoop/serialisation/avro/dto/SchemaRegistry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package kafkasnoop.serialisation.avro.dto | ||
|
||
import com.papsign.ktor.openapigen.annotations.Response | ||
|
||
@Response("AVRO Schema Registry") | ||
data class SchemaRegistry( | ||
val schemas: List<Schema>, | ||
val failedToParse: List<FailedToParseSchema> | ||
) | ||
|
||
data class Schema( | ||
val name: String, | ||
val sha256FingerPrint: String, | ||
val aliases: List<String>, | ||
val type: String, | ||
val fields: List<String>, | ||
val contentUrl: String, | ||
) | ||
|
||
data class FailedToParseSchema(val name: String, val dependencies: List<String>) |
57 changes: 57 additions & 0 deletions
57
http/serialisation/avro/src/main/kotlin/kafkasnoop/serialisation/avro/routes/schemas.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package kafkasnoop.serialisation.avro.routes | ||
|
||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonParser | ||
import com.papsign.ktor.openapigen.annotations.parameters.PathParam | ||
import com.papsign.ktor.openapigen.route.info | ||
import com.papsign.ktor.openapigen.route.path.normal.NormalOpenAPIRoute | ||
import com.papsign.ktor.openapigen.route.path.normal.get | ||
import com.papsign.ktor.openapigen.route.response.respond | ||
import io.ktor.features.* | ||
import kafkasnoop.avro.SchemaRegistry | ||
import kafkasnoop.serialisation.avro.dto.FailedToParseSchema | ||
import kafkasnoop.serialisation.avro.dto.Schema | ||
import java.net.URLEncoder | ||
|
||
fun NormalOpenAPIRoute.schemas( | ||
schemaRegistry: SchemaRegistry | ||
) { | ||
get<Unit, kafkasnoop.serialisation.avro.dto.SchemaRegistry>( | ||
info("Schema Registry", "Get details of all schemas in the registry") | ||
) { | ||
respond( | ||
kafkasnoop.serialisation.avro.dto.SchemaRegistry( | ||
schemaRegistry.all.map { | ||
val fields = if (it.type == org.apache.avro.Schema.Type.ENUM) { | ||
emptyList() | ||
} else { | ||
it.fields.map { f -> "${f.name() ?: ""}[${f.schema().fullName}]" } | ||
} | ||
Schema( | ||
it.fullName, | ||
schemaRegistry.getBase64FingerPrintFor(it.fullName) ?: "", | ||
it.aliases.toList(), | ||
it.type.name, | ||
fields, | ||
"/api/schemas/${URLEncoder.encode(it.fullName, Charsets.UTF_8)}", | ||
) | ||
}, | ||
schemaRegistry.failedToParse.map { s -> FailedToParseSchema(s.fullName, s.needs) } | ||
) | ||
) | ||
} | ||
} | ||
|
||
data class SchemaNameParam(@PathParam("Schema Full Name") val name: String) | ||
|
||
fun NormalOpenAPIRoute.schemaByName(schemaRegistry: SchemaRegistry) { | ||
get<SchemaNameParam, JsonElement>( | ||
info("Schema Content", "Get details of all schemas in the registry") | ||
) { param -> | ||
val schema = schemaRegistry.getByName(param.name) | ||
?: throw NotFoundException("Schema with name ${param.name} not found") | ||
respond( | ||
JsonParser.parseString(schema.toString(true)) | ||
) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...lisation/avro/src/main/kotlin/kafkasnoop/serialisation/avro/routes/serialiserApiRoutes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package kafkasnoop.serialisation.avro.routes | ||
|
||
import com.papsign.ktor.openapigen.route.path.normal.NormalOpenAPIRoute | ||
import com.papsign.ktor.openapigen.route.route | ||
import kafkasnoop.avro.SchemaRegistry | ||
|
||
fun NormalOpenAPIRoute.serialiserApiRoutes( | ||
schemaRegistry: SchemaRegistry, | ||
) { | ||
route("/api/schemas").schemas(schemaRegistry) | ||
route("/api/schemas/{name}").schemaByName(schemaRegistry) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters