1414import java .nio .file .Path ;
1515import java .nio .file .Paths ;
1616import java .util .ArrayList ;
17+ import java .util .HashMap ;
1718import java .util .List ;
19+ import java .util .Map ;
1820import java .util .stream .Stream ;
1921
2022@ Singleton
@@ -24,6 +26,7 @@ public class SchemaService {
2426 private static final String SCHEMA_DIRECTORY = "schemas" ;
2527
2628 private final List <SchemaInfo > schemas = new ArrayList <>();
29+ private final Map <String , String > schemaContents = new HashMap <>();
2730 private final ObjectMapper objectMapper = new ObjectMapper ();
2831
2932 @ PostConstruct
@@ -78,6 +81,8 @@ private void loadSchemaMetadata(Path metadataPath) {
7881 Path schemaFilePath = metadataPath .getParent ().resolve (schemaFileName );
7982
8083 if (Files .exists (schemaFilePath )) {
84+ String schemaContent = Files .readString (schemaFilePath , StandardCharsets .UTF_8 );
85+ schemaContents .put (schemaInfo .getId (), schemaContent );
8186 schemas .add (schemaInfo );
8287 LOG .debug ("Loaded schema: {}" , schemaInfo .getId ());
8388 } else {
@@ -91,5 +96,15 @@ private void loadSchemaMetadata(Path metadataPath) {
9196 public List <SchemaInfo > listSchemas () {
9297 return new ArrayList <>(schemas );
9398 }
99+
100+ public String getSchema (String schemaId ) throws Exception {
101+ String content = schemaContents .get (schemaId );
102+
103+ if (content == null ) {
104+ throw new Exception ("Schema not found: " + schemaId );
105+ }
106+
107+ return content ;
108+ }
94109}
95110
0 commit comments