Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private void processRecord(HttpResponseParam record) throws Exception {

// Evaluate filter first (ignore and filter are independent conditions)
// SchemaConform check is disabled
if(false && apiFilter.getInfo().getCategory().getName().equalsIgnoreCase("SchemaConform")) {
if(apiFilter.getInfo().getCategory().getName().equalsIgnoreCase("SchemaConform")) {
logger.debug("SchemaConform filter found for url {} filterId {}", apiInfoKey.getUrl(), apiFilter.getId());
String apiSchema = getApiSchema(apiCollectionId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ private static boolean matchesParameterizedPath(String pathKey, String url) {
// TODO: handle cases like
// /pets/{petId} and /pets/mine both are present in schema

// Strip query parameters and fragments from URL
int queryIndex = url.indexOf('?');
if (queryIndex != -1) {
url = url.substring(0, queryIndex);
}
int fragmentIndex = url.indexOf('#');
if (fragmentIndex != -1) {
url = url.substring(0, fragmentIndex);
}

// Remove trailing slash for consistent matching
if (url.endsWith("/") && url.length() > 1) {
url = url.substring(0, url.length() - 1);
}
if (pathKey.endsWith("/") && pathKey.length() > 1) {
pathKey = pathKey.substring(0, pathKey.length() - 1);
}

String[] pathSegments = pathKey.split("/");
String[] urlSegments = url.split("/");

Expand Down Expand Up @@ -126,17 +144,18 @@ public static JsonNode getRequestBodySchemaNode(JsonNode rootSchemaNode, HttpRes
}

// Skip request body validation for GET/DELETE requests
String method = responseParam.getRequestParams().getMethod().toLowerCase();
if(method.equals("get") || method.equals("delete")){
return null;
}
// String method = responseParam.getRequestParams().getMethod().toLowerCase();
// if(method.equals("get") || method.equals("delete")){
// return null;
// }

JsonNode requestBodyNode = getRequestBodyNode(methodNode, url, responseParam);
if (requestBodyNode == null) {
return null;
}
// JsonNode requestBodyNode = getRequestBodyNode(methodNode, url, responseParam);
// if (requestBodyNode == null) {
// return null;
// }

return getContentSchemaNode(requestBodyNode, responseParam);
// return getContentSchemaNode(requestBodyNode, responseParam);
return methodNode;
}

private static JsonNode getPathNode(JsonNode rootSchemaNode, String url, HttpResponseParams responseParam) {
Expand Down Expand Up @@ -233,33 +252,33 @@ private static List<SchemaConformanceError> validateRequestBody(HttpResponsePara
return errors;
}

JsonNode dataNode = objectMapper.readTree(httpResponseParams.getRequestParams().getPayload());
// JsonNode dataNode = objectMapper.readTree(httpResponseParams.getRequestParams().getPayload());

JsonSchema schema = factory.getSchema(schemaNode);
// JsonSchema schema = factory.getSchema(schemaNode);

Set<ValidationMessage> validationMessages = schema.validate(dataNode);
// Set<ValidationMessage> validationMessages = schema.validate(dataNode);

if (validationMessages.isEmpty()) {
// if (validationMessages.isEmpty()) {

return errors;
}
// return errors;
// }

logger.debug("Request not conforming to schema for api collection id {}",
httpResponseParams.getRequestParams().getApiCollectionId());
// logger.debug("Request not conforming to schema for api collection id {}",
// httpResponseParams.getRequestParams().getApiCollectionId());

errors.clear();
for (ValidationMessage message : validationMessages) {
errorBuilder.clear();
errorBuilder.setSchemaPath(message.getSchemaLocation().toString());
errorBuilder.setInstancePath(message.getInstanceLocation().toString());
errorBuilder.setAttribute("requestBody");
errorBuilder.setMessage(message.getMessage());
errorBuilder.setLocation(SchemaConformanceError.Location.LOCATION_BODY);
errorBuilder.setStart(-1);
errorBuilder.setEnd(-1);
errorBuilder.setPhrase(message.getMessage());
errors.add(errorBuilder.build());
}
// errors.clear();
// for (ValidationMessage message : validationMessages) {
// errorBuilder.clear();
// errorBuilder.setSchemaPath(message.getSchemaLocation().toString());
// errorBuilder.setInstancePath(message.getInstanceLocation().toString());
// errorBuilder.setAttribute("requestBody");
// errorBuilder.setMessage(message.getMessage());
// errorBuilder.setLocation(SchemaConformanceError.Location.LOCATION_BODY);
// errorBuilder.setStart(-1);
// errorBuilder.setEnd(-1);
// errorBuilder.setPhrase(message.getMessage());
// errors.add(errorBuilder.build());
// }

return errors;
}
Expand Down
Loading
Loading