diff --git a/crates/context_aware_config/src/api/default_config/handlers.rs b/crates/context_aware_config/src/api/default_config/handlers.rs index df3754d7..7d38ffa1 100644 --- a/crates/context_aware_config/src/api/default_config/handlers.rs +++ b/crates/context_aware_config/src/api/default_config/handlers.rs @@ -18,7 +18,7 @@ use crate::{ models::{Context, DefaultConfig}, schema::{contexts::dsl::contexts, default_configs::dsl}, }, - helpers::{add_config_version, validate_jsonschema}, + helpers::add_config_version, }; use actix_web::{ delete, get, put, @@ -137,11 +137,6 @@ async fn create( last_modified_by: user.get_email(), }; - validate_jsonschema( - &state.default_config_validation_schema, - &default_config.schema, - )?; - let schema_compile_result = JSONSchema::options() .with_draft(Draft::Draft7) .compile(&default_config.schema); diff --git a/crates/context_aware_config/src/helpers.rs b/crates/context_aware_config/src/helpers.rs index 85dfe205..afeb03b8 100644 --- a/crates/context_aware_config/src/helpers.rs +++ b/crates/context_aware_config/src/helpers.rs @@ -30,75 +30,6 @@ use superposition_types::{result as superposition, Cac, Condition, Overrides}; use std::collections::HashMap; -pub fn get_default_config_validation_schema() -> JSONSchema { - let my_schema = json!( - { - "type": "object", - "properties": { - "type": { - "anyOf": [ - { - "type": "null" - }, - { - "type": "string" - }, - { - "type": "object" - }, - { - "type": "number" - }, - { - "type": "boolean" - }, - { - "type": "array" - } - ] - } - }, - "required": [ - "type" - ], - "allOf": [ - { - "if": { - "properties": { - "type": { - "const": "string" - } - } - }, - "then": { - "oneOf": [ - { - "required": ["pattern"], - "properties": { "pattern": { "type": "string" } } - }, - { - "required": ["enum"], - "properties": { - "enum": { - "type": "array", - "contains": { "type": "string" }, - "minContains": 1 - }, - } - } - ] - } - } - // TODO: Add validations for Array types. - ] - }); - - JSONSchema::options() - .with_draft(Draft::Draft7) - .compile(&my_schema) - .expect("THE IMPOSSIBLE HAPPENED, failed to compile the schema for the schema!") -} - pub fn parse_headermap_safe(headermap: &HeaderMap) -> HashMap { let mut req_headers = HashMap::new(); let record_header = |(header_name, header_val): (&HeaderName, &HeaderValue)| { @@ -123,33 +54,10 @@ pub fn get_meta_schema() -> JSONSchema { "type": "object", "properties": { "type": { - "enum": ["boolean", "number", "string"] + "enum": ["boolean", "number", "integer", "string", "array", "null"] }, }, "required": ["type"], - - // # Add extra validation if needed for other primitive data types - "if": { - "properties": { "type": { "const": "string" } } - } - , "then": { - "oneOf": [ - { - "required": ["pattern"], - "properties": { "pattern": { "type": "string" } } - }, - { - "required": ["enum"], - "properties": { - "enum": { - "type": "array", - "contains": { "type": "string" }, - "minContains": 1 - }, - } - } - ] - } }); JSONSchema::options() @@ -415,16 +323,6 @@ mod tests { let ok_string_validation = x.validate(&ok_string_schema); assert!(ok_string_validation.is_ok()); - let error_string_schema = json!({"type": "string"}); - let error_string_validation = x.validate(&error_string_schema).map_err(|e| { - let verrors = e.collect::>(); - format!( - "Error While validating string dataType, Bad schema: {:?}", - verrors.as_slice() - ) - }); - assert!(error_string_validation.is_err_and(|error| error.contains("Bad schema"))); - let error_object_schema = json!({"type": "object"}); let error_object_validation = x.validate(&error_object_schema).map_err(|e| { let verrors = e.collect::>(); diff --git a/crates/experimentation_platform/src/api/experiments/types.rs b/crates/experimentation_platform/src/api/experiments/types.rs index 4896213a..9061b5a4 100644 --- a/crates/experimentation_platform/src/api/experiments/types.rs +++ b/crates/experimentation_platform/src/api/experiments/types.rs @@ -102,7 +102,7 @@ pub struct ConcludeExperimentRequest { #[derive(Deserialize, Serialize, Clone)] pub struct ContextPutReq { - pub context: serde_json::Map, + pub context: Map, pub r#override: Value, } @@ -165,7 +165,7 @@ pub struct OverrideKeysUpdateRequest { #[derive(Deserialize, Serialize, Clone)] pub struct ContextMoveReq { - pub context: serde_json::Map, + pub context: Map, } /*********** List Audit API Filter Type **************/ diff --git a/crates/service_utils/src/service/types.rs b/crates/service_utils/src/service/types.rs index 4fa511b9..40fd6be9 100644 --- a/crates/service_utils/src/service/types.rs +++ b/crates/service_utils/src/service/types.rs @@ -43,7 +43,6 @@ pub struct AppState { pub tenants: HashSet, pub cac_version: String, pub db_pool: PgSchemaManager, - pub default_config_validation_schema: JSONSchema, pub meta_schema: JSONSchema, pub experimentation_flags: ExperimentationFlags, pub snowflake_generator: Arc>, diff --git a/crates/superposition/src/main.rs b/crates/superposition/src/main.rs index 3b095fec..58a4a0d1 100644 --- a/crates/superposition/src/main.rs +++ b/crates/superposition/src/main.rs @@ -2,9 +2,7 @@ use actix_web::dev::Service; use actix_web::HttpMessage; use actix_web::{web, web::get, web::scope, web::Data, App, HttpResponse, HttpServer}; use context_aware_config::api::*; -use context_aware_config::helpers::{ - get_default_config_validation_schema, get_meta_schema, -}; +use context_aware_config::helpers::get_meta_schema; use experimentation_platform::api::*; use std::sync::Arc; use std::{collections::HashSet, io::Result}; @@ -144,7 +142,6 @@ async fn main() -> Result<()> { .wrap(TenantMiddlewareFactory) .app_data(Data::new(AppState { db_pool: schema_manager.clone(), - default_config_validation_schema: get_default_config_validation_schema(), cac_host: cac_host.to_owned(), cac_version: cac_version.to_owned(),