From 22b369672f04ca397d0c4e5cc43e543a04705fd4 Mon Sep 17 00:00:00 2001 From: Neil Avery Date: Fri, 15 Mar 2024 15:32:21 +0000 Subject: [PATCH] support schema comments (#286) * support schema comments * support schema comments --------- Co-authored-by: navery-max --- .../specmesh/kafka/provision/schema/SchemaReaders.java | 9 +++++++-- .../schema-ref/schema/com.example.trading.Trade.avsc | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/kafka/src/main/java/io/specmesh/kafka/provision/schema/SchemaReaders.java b/kafka/src/main/java/io/specmesh/kafka/provision/schema/SchemaReaders.java index ffbc72ed..a5fee1f2 100644 --- a/kafka/src/main/java/io/specmesh/kafka/provision/schema/SchemaReaders.java +++ b/kafka/src/main/java/io/specmesh/kafka/provision/schema/SchemaReaders.java @@ -16,6 +16,7 @@ package io.specmesh.kafka.provision.schema; +import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -47,6 +48,11 @@ /** Readers for reading Schemas */ public final class SchemaReaders { + private static final ObjectMapper objectMapper = new ObjectMapper(); + + static { + objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); + } /** defensive */ private SchemaReaders() {} @@ -99,8 +105,7 @@ private SchemaReferences resolveReferencesFor( final String filePath, final String schemaContent) { try { final SchemaReferences results = new SchemaReferences(); - final var refs = - findJsonNodes(new ObjectMapper().readTree(schemaContent), "subject"); + final var refs = findJsonNodes(objectMapper.readTree(schemaContent), "subject"); final var parent = new File(filePath).getParent(); refs.forEach(ref -> results.add(parent, ref)); return results; diff --git a/kafka/src/test/resources/schema-ref/schema/com.example.trading.Trade.avsc b/kafka/src/test/resources/schema-ref/schema/com.example.trading.Trade.avsc index 365451d0..9dff5db2 100644 --- a/kafka/src/test/resources/schema-ref/schema/com.example.trading.Trade.avsc +++ b/kafka/src/test/resources/schema-ref/schema/com.example.trading.Trade.avsc @@ -13,6 +13,7 @@ { "name": "detail", "type": "string", "doc": "Trade details." }, +// some comment - works { "name": "currency", "type": "com.example.shared.Currency",