removed schema realms, fixed fixture generations, added dynamic type resolution for validation based on type and kind discriminators for filters

This commit is contained in:
2026-04-21 10:50:01 -04:00
parent a1e6ac8cb0
commit 4e2cb488cc
25 changed files with 440 additions and 331 deletions

View File

@ -1,5 +1,4 @@
use crate::database::Database;
use crate::database::realm::SchemaRealm;
use std::sync::Arc;
pub struct Compiler<'a> {
@ -25,15 +24,11 @@ pub struct Node<'a> {
impl<'a> Compiler<'a> {
/// Compiles a JSON schema into a nested PostgreSQL query returning JSONB
pub fn compile(&self, schema_id: &str, filter_keys: &[String]) -> Result<String, String> {
let realm = if schema_id.ends_with(".request") || schema_id.ends_with(".response") {
SchemaRealm::Punc
} else {
SchemaRealm::Type
};
let schema = self
.db
.get_scoped_schema(realm, schema_id)
.schemas
.get(schema_id)
.cloned()
.ok_or_else(|| format!("Schema not found: {}", schema_id))?;
let target_schema = schema;
@ -157,7 +152,7 @@ impl<'a> Compiler<'a> {
if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) = &node.schema.obj.type_ {
if !crate::database::object::is_primitive_type(t) {
// If it's just an ad-hoc struct ref, we should resolve it
if let Some(target_schema) = self.db.get_scoped_schema(SchemaRealm::Type, t) {
if let Some(target_schema) = self.db.schemas.get(t).cloned() {
let mut ref_node = node.clone();
ref_node.schema = target_schema.clone();
ref_node.schema_id = Some(t.clone());
@ -312,7 +307,7 @@ impl<'a> Compiler<'a> {
for (disc_val, (idx_opt, target_id_opt)) in options {
if let Some(target_id) = target_id_opt {
if let Some(target_schema) = self.db.get_scoped_schema(SchemaRealm::Type, target_id) {
if let Some(target_schema) = self.db.schemas.get(target_id).cloned() {
let mut child_node = node.clone();
child_node.schema = target_schema.clone();
child_node.schema_id = Some(target_id.clone());