private void writeSchema(Map<String, String> detectedFields) throws IOException {
        Path schemaPath = Paths.get("schemas", "document_type.sd");
        String schema = readTemplate(schemaPath.toString());
        // replace document_type in schema with the actual document type
        schema = schema.replace("document_type", config.getDocumentType());
        
        // This is where we accumulate field definitions for both "main" and "synthetic" fields
        StringBuilder documentFieldsBuilder = new StringBuilder();
        StringBuilder syntheticFieldsBuilder = new StringBuilder();
        
        for (Map.Entry<String, String> entry : detectedFields.entrySet()) {
            String fieldName = entry.getKey();
            String fieldType = entry.getValue();
            String arraySize = null;

            if (fieldType.contains("[")) {
                // array field, we need to extract the size
                String[] parts = fieldType.split("\\[");
                arraySize = parts[1].replace("]", "");
                fieldType = parts[0];
            }
            
            List<String> fieldTemplates = typeMappings.get(fieldType);
            if (fieldTemplates != null && !fieldTemplates.isEmpty()) {
                // First template goes into the document block
                documentFieldsBuilder.append(processTemplate(fieldTemplates.get(0),
                                            fieldName, fieldType, arraySize, true));
                
                // Additional templates are synthetic fields
                for (int i = 1; i < fieldTemplates.size(); i++) {
                    syntheticFieldsBuilder.append(processTemplate(fieldTemplates.get(i),
                                            fieldName, fieldType, arraySize, false));
                }
            } else {
                logger.warn("No mapping found for field {} of type {}", fieldName, fieldType);
            }
        }
        
        // Replace placeholders with generated fields, removing the last newline
        String documentFields = removeTrailingNewline(documentFieldsBuilder.toString());
        String syntheticFields = removeTrailingNewline(syntheticFieldsBuilder.toString());
        
        schema = schema.replace("        # Fields will be added here", documentFields)
                      .replace("    # synthetic fields can be added here", syntheticFields);

        writeSchemaFile(schema, config.getDocumentType());
    }
Writes the schema file by replacing template placeholders with definitions of detected fields.

@param detectedFields The fields detected in the input data
@throws IOException if an error occurs while writing the schema file
integration/logstash-plugins/logstash-output-vespa/src/main/java/org/logstashplugins/VespaAppPackageWriter.java