forked from modelcontextprotocol/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonSchemaValidator.java
More file actions
45 lines (37 loc) · 1.45 KB
/
JsonSchemaValidator.java
File metadata and controls
45 lines (37 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* Copyright 2024-2024 the original author or authors.
*/
package io.modelcontextprotocol.spec;
import java.util.Map;
/**
* Interface for validating structured content against a JSON schema. This interface
* defines a method to validate structured content based on the provided output schema.
*
* @author Christian Tzolov
*/
public interface JsonSchemaValidator {
/**
* Represents the result of a validation operation.
*
* @param valid Indicates whether the validation was successful.
* @param errorMessage An error message if the validation failed, otherwise null.
* @param jsonStructuredOutput The text structured content in JSON format if the
* validation was successful, otherwise null.
*/
public record ValidationResponse(boolean valid, String errorMessage, String jsonStructuredOutput) {
public static ValidationResponse asValid(String jsonStructuredOutput) {
return new ValidationResponse(true, null, jsonStructuredOutput);
}
public static ValidationResponse asInvalid(String message) {
return new ValidationResponse(false, message, null);
}
}
/**
* Validates the structured content against the provided JSON schema.
* @param schema The JSON schema to validate against.
* @param structuredContent The structured content to validate.
* @return A ValidationResponse indicating whether the validation was successful or
* not.
*/
ValidationResponse validate(Map<String, Object> schema, Object structuredContent);
}