Fix PathItem bug #7
@ -71,7 +71,7 @@ public class MockFileLoader {
|
||||
@Scheduled(fixedDelayString = "${mock.reload-interval-ms}")
|
||||
public void reloadIfChanged() {
|
||||
if (hasChanged()) {
|
||||
LOGGER.info("🔄 Reloading mock files...");
|
||||
LOGGER.info("Reloading mock files...");
|
||||
reload();
|
||||
}
|
||||
}
|
||||
@ -135,7 +135,7 @@ public class MockFileLoader {
|
||||
|
||||
openApiService.rebuild(endpoints);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("❌ Failed to reload mock files: {}", e.getMessage());
|
||||
LOGGER.error("Failed to reload mock files: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@ public class MockFileLoader {
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("❌ Failed to load globals from {}: {}", file, e.getMessage());
|
||||
LOGGER.error("Failed to load globals from {}: {}", file, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,13 +55,13 @@ public class MockFileParser {
|
||||
|
||||
// Handle empty file
|
||||
if (root == null) {
|
||||
LOGGER.warn("⚠️ Skipping empty YAML file: {}", file);
|
||||
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());
|
||||
LOGGER.error("Expected a YAML list in file: {} but got {}", file, root.getClass().getSimpleName());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -82,12 +82,12 @@ public class MockFileParser {
|
||||
endpoints.add(endpoint);
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("⚠️ Skipping invalid endpoint in " + file + ": " + e.getMessage());
|
||||
LOGGER.error("Skipping invalid endpoint in " + file + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("❌ Failed to parse " + file + ": " + e.getMessage());
|
||||
LOGGER.error("Failed to parse " + file + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,28 +53,28 @@ public class OpenApiService {
|
||||
.tags(List.of(extractTag(path)))
|
||||
.parameters(pathParams(path));
|
||||
|
||||
PathItem item = getPathItem(endpoint, operation);
|
||||
// Check if PathItem already exists for this path
|
||||
PathItem item = api.getPaths().get(path);
|
||||
if (item == null) {
|
||||
item = new PathItem();
|
||||
}
|
||||
|
||||
// Add operation to existing PathItem based on method
|
||||
HttpMethod method = endpoint.getMethod();
|
||||
switch (method) {
|
||||
case GET -> item.get(operation);
|
||||
case POST -> item.post(operation);
|
||||
case PUT -> item.put(operation);
|
||||
case DELETE -> item.delete(operation);
|
||||
case PATCH -> item.patch(operation);
|
||||
default -> throw new IllegalArgumentException("Unsupported HTTP method: " + method);
|
||||
}
|
||||
|
||||
api.getPaths().addPathItem(path, item);
|
||||
}
|
||||
this.openAPI = api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an OpenAPI {@link PathItem} object for a given mock endpoint and operation.
|
||||
* @param endpoint the mock endpoint to describe
|
||||
* @param operation the operation to associate with the endpoint
|
||||
* @return the generated {@link PathItem}
|
||||
*/
|
||||
private static PathItem getPathItem(MockEndpoint endpoint, Operation operation) {
|
||||
HttpMethod method = endpoint.getMethod();
|
||||
return switch (method) {
|
||||
case GET -> new PathItem().get(operation);
|
||||
case POST -> new PathItem().post(operation);
|
||||
case PUT -> new PathItem().put(operation);
|
||||
case DELETE -> new PathItem().delete(operation);
|
||||
case PATCH -> new PathItem().patch(operation);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the most recently built OpenAPI specification.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user