Add index-support, type hints and improve documentation #4

Merged
stne3960 merged 3 commits from feature/allow_index into main 2025-06-16 12:41:04 +02:00
Showing only changes of commit 443fd93b5e - Show all commits

View File

@ -46,9 +46,24 @@ public class MockFileParser {
*/ */
public void parseFile(Path file, String relativePath, List<MockEndpoint> endpoints, MockValidator validator) { public void parseFile(Path file, String relativePath, List<MockEndpoint> endpoints, MockValidator validator) {
String basePath = "/" + relativePath; String basePath = "/" + relativePath;
if (basePath.endsWith("/index")) {
basePath = basePath.substring(0, basePath.length() - "/index".length());
}
try (InputStream input = Files.newInputStream(file)) { try (InputStream input = Files.newInputStream(file)) {
List<?> rawList = yaml.load(input); Object root = yaml.load(input);
// Handle empty file
if (root == null) {
LOGGER.warn("⚠️ Skipping empty YAML file: {}", file);
return;
}
// Ensure the root YAML object is a list
if (!(root instanceof List<?> rawList)) {
LOGGER.error("❌ Expected a YAML list in file: {} but got {}", file, root.getClass().getSimpleName());
return;
}
for (Object obj : rawList) { for (Object obj : rawList) {
try { try {