Skip to content
Merged
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
10 changes: 7 additions & 3 deletions src/main/java/ai/rhesis/sdk/synthesizers/SchemaBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static Map<String, Object> buildFlatTestsSchema(
items.put("type", "object");
items.put("properties", properties);
items.put("required", requiredFields);
items.put("additionalProperties", false);

Map<String, Object> testsProp = new HashMap<>();
testsProp.put("type", "array");
Expand All @@ -22,9 +23,12 @@ public static Map<String, Object> buildFlatTestsSchema(

Map<String, Object> jsonSchema = new HashMap<>();
jsonSchema.put("name", "FlatTests");
jsonSchema.put(
"schema",
Map.of("type", "object", "properties", schemaProps, "required", List.of("tests")));
Map<String, Object> schema = new HashMap<>();
schema.put("type", "object");
schema.put("properties", schemaProps);
schema.put("required", List.of("tests"));
schema.put("additionalProperties", false);
jsonSchema.put("schema", schema);
jsonSchema.put("strict", true);

Map<String, Object> rootSchema = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ai.rhesis.sdk.unit.synthesizers;

import static org.junit.jupiter.api.Assertions.*;

import ai.rhesis.sdk.synthesizers.SchemaBuilder;
import java.util.Map;
import org.junit.jupiter.api.Test;

class SchemaBuilderTest {

@Test
@SuppressWarnings("unchecked")
void singleTurnSchemaHasAdditionalPropertiesFalseAtAllLevels() {
Map<String, Object> root = SchemaBuilder.buildSingleTurnSchema();
Map<String, Object> jsonSchema = (Map<String, Object>) root.get("json_schema");
Map<String, Object> schema = (Map<String, Object>) jsonSchema.get("schema");

assertEquals(false, schema.get("additionalProperties"), "root schema object");

Map<String, Object> props = (Map<String, Object>) schema.get("properties");
Map<String, Object> tests = (Map<String, Object>) props.get("tests");
Map<String, Object> items = (Map<String, Object>) tests.get("items");

assertEquals(false, items.get("additionalProperties"), "test item object");
}

@Test
@SuppressWarnings("unchecked")
void multiTurnSchemaHasAdditionalPropertiesFalseAtAllLevels() {
Map<String, Object> root = SchemaBuilder.buildMultiTurnSchema();
Map<String, Object> jsonSchema = (Map<String, Object>) root.get("json_schema");
Map<String, Object> schema = (Map<String, Object>) jsonSchema.get("schema");

assertEquals(false, schema.get("additionalProperties"), "root schema object");

Map<String, Object> props = (Map<String, Object>) schema.get("properties");
Map<String, Object> tests = (Map<String, Object>) props.get("tests");
Map<String, Object> items = (Map<String, Object>) tests.get("items");

assertEquals(false, items.get("additionalProperties"), "test item object");
}
}
Loading