@@ -130,25 +130,25 @@ const routeSchema = yup.object().shape({
130130} ) ;
131131
132132const validRouteSchema = yup
133- . mixed ( )
133+ . object ( )
134134 . test ( "valid-route" , "Valid route is required" , function ( value ) {
135135 const configSchema = this . from . slice ( - 1 ) . pop ( ) ;
136136 const { routes } = configSchema . value . config ;
137137 return routes . map ( ( r ) => r . id ) . includes ( value ) ;
138138 } ) ;
139139
140140const ruleConditionSchema = yup . object ( ) . shape ( {
141- field_source : fieldSourceSchema ,
142- field : fieldSchema ( "field_source" ) ,
141+ field_source : fieldSourceSchema ( ) ,
142+ field : fieldSchema ( "field_source" ) ( ) ,
143143 operator : yup
144- . mixed ( )
144+ . string ( )
145145 . oneOf ( [ "in" ] , "One of supported operators should be specified" ) ,
146146 values : yup
147147 . array ( yup . string ( ) )
148- . required ( "At least one value should be provided" ) ,
148+ . min ( 1 , "At least one value should be provided" ) ,
149149} ) ;
150150
151- const defaultTrafficRuleSchema = yup . object ( ) . shape ( {
151+ const defaultTrafficRuleSchema = ( _ ) => yup . object ( ) . shape ( {
152152 routes : yup
153153 . array ( )
154154 . of ( validRouteSchema )
@@ -244,7 +244,7 @@ const autoscalingPolicySchema = yup.object().shape({
244244
245245const enricherSchema = yup . object ( ) . shape ( {
246246 type : yup
247- . mixed ( )
247+ . string ( )
248248 . required ( "Valid Enricher type should be selected" )
249249 . oneOf ( [ "nop" , "docker" ] , "Valid Enricher type should be selected" ) ,
250250} ) ;
@@ -256,7 +256,7 @@ const dockerImageSchema = yup
256256 "Valid Docker Image value should be provided, e.g. kennethreitz/httpbin:latest"
257257 ) ;
258258
259- const dockerDeploymentSchema = ( maxAllowedReplica ) =>
259+ const dockerDeploymentSchema = ( maxAllowedReplica ) => ( _ ) =>
260260 yup . object ( ) . shape ( {
261261 image : dockerImageSchema . required ( "Docker Image is required" ) ,
262262 endpoint : yup . string ( ) . required ( "Endpoint value is required" ) ,
@@ -271,7 +271,7 @@ const dockerDeploymentSchema = (maxAllowedReplica) =>
271271 autoscaling_policy : autoscalingPolicySchema ,
272272 } ) ;
273273
274- const pyfuncDeploymentSchema = ( maxAllowedReplica ) =>
274+ const pyfuncDeploymentSchema = ( maxAllowedReplica ) => ( _ ) =>
275275 yup . object ( ) . shape ( {
276276 project_id : yup . number ( ) . integer ( ) . required ( "Project ID is required" ) ,
277277 ensembler_id : yup . number ( ) . integer ( ) . required ( "Ensembler ID is required" ) ,
@@ -287,7 +287,7 @@ const mappingSchema = yup.object().shape({
287287 route : yup . string ( ) . required ( "Treatment needs to be mapped back to a route" ) ,
288288} ) ;
289289
290- const standardEnsemblerConfigSchema = yup
290+ const standardEnsemblerConfigSchema = ( _ ) => yup
291291 . object ( )
292292 . shape ( {
293293 route_name_path : yup . string ( ) . nullable ( ) ,
@@ -310,7 +310,7 @@ const standardEnsemblerConfigSchema = yup
310310 }
311311 ) ;
312312
313- const bigQueryConfigSchema = yup . object ( ) . shape ( {
313+ const bigQueryConfigSchema = ( _ ) => yup . object ( ) . shape ( {
314314 table : yup
315315 . string ( )
316316 . required ( "BigQuery table name is required" )
@@ -321,7 +321,7 @@ const bigQueryConfigSchema = yup.object().shape({
321321 service_account_secret : yup . string ( ) . required ( "Service Account is required" ) ,
322322} ) ;
323323
324- const kafkaConfigSchema = yup . object ( ) . shape ( {
324+ const kafkaConfigSchema = ( _ ) => yup . object ( ) . shape ( {
325325 brokers : yup
326326 . string ( )
327327 . required ( "Kafka broker(s) is required" )
@@ -337,7 +337,7 @@ const kafkaConfigSchema = yup.object().shape({
337337 "A valid Kafka topic name may only contain letters, numbers, dot, hyphen or underscore"
338338 ) ,
339339 serialization_format : yup
340- . mixed ( )
340+ . string ( )
341341 . required ( "Serialzation format should be selected" )
342342 . oneOf (
343343 [ "json" , "protobuf" ] ,
@@ -364,10 +364,9 @@ const schema = (maxAllowedReplica) => [
364364 . test ( "unique-rule-names" , validateRuleNames ) ,
365365 routes : yup
366366 . array ( routeSchema )
367- . required ( )
368367 . unique ( "id" , "Route Id must be unique" )
369368 . min ( 1 , "At least one route should be configured" )
370- . when ( [ "rules" ] , ( rules , schema ) => {
369+ . when ( [ "rules" ] , ( [ rules ] , schema ) => {
371370 if ( rules . length > 0 ) {
372371 return schema . test ( "no-dangling-routes" , validateDanglingRoutes ) ;
373372 }
@@ -391,20 +390,19 @@ const schema = (maxAllowedReplica) => [
391390 config : yup . object ( ) . shape ( {
392391 experiment_engine : yup . object ( ) . shape ( {
393392 type : yup
394- . mixed ( )
393+ . string ( )
395394 . required ( "Valid Experiment Engine should be selected" )
396- . when ( "$experimentEngineOptions" , ( options , schema ) =>
395+ . when ( "$experimentEngineOptions" , ( [ options ] , schema ) =>
397396 schema . oneOf ( options , "Valid Experiment Engine should be selected" )
398397 ) ,
399- config : yup . mixed ( ) . when ( "type" , ( engine , schema ) =>
398+ config : yup . object ( ) . when ( "type" , ( [ engine ] , schema ) =>
400399 engine === "nop"
401400 ? schema
402- : yup
403- . mixed ( )
404- . when ( "$getEngineProperties" , ( getEngineProperties ) => {
401+ : schema
402+ . when ( "$getEngineProperties" , ( [ getEngineProperties ] , schema ) => {
405403 const engineProps = getEngineProperties ( engine ) ;
406404 return engineProps . type === "standard"
407- ? standardExperimentConfigSchema ( engineProps )
405+ ? standardExperimentConfigSchema ( engineProps ) ( schema )
408406 : engineProps . custom_experiment_manager_config
409407 ?. parsed_experiment_config_schema || schema ;
410408 } )
@@ -418,7 +416,7 @@ const schema = (maxAllowedReplica) => [
418416 switch ( value . type ) {
419417 case "docker" :
420418 return enricherSchema . concat (
421- dockerDeploymentSchema ( maxAllowedReplica )
419+ dockerDeploymentSchema ( maxAllowedReplica ) ( )
422420 ) ;
423421 default :
424422 return enricherSchema ;
@@ -430,27 +428,30 @@ const schema = (maxAllowedReplica) => [
430428 config : yup . object ( ) . shape ( {
431429 ensembler : yup . object ( ) . shape ( {
432430 type : yup
433- . mixed ( )
431+ . string ( )
434432 . required ( "Valid Ensembler type should be selected" )
435433 . oneOf (
436434 [ "nop" , "docker" , "standard" , "pyfunc" ] ,
437435 "Valid Ensembler type should be selected"
438436 ) ,
439- nop_config : yup . mixed ( ) . when ( "type" , {
437+ nop_config : yup . object ( ) . when ( "type" , {
440438 is : "nop" ,
441- then : yup . object ( ) . shape ( {
439+ then : ( _ ) => yup . object ( ) . shape ( {
442440 final_response_route_id : validRouteSchema ,
443441 } ) ,
444442 } ) ,
445- docker_config : yup . mixed ( ) . when ( "type" , {
443+ some_field : yup . string ( ) . when ( "some_other_field" , ( [ some_other_field ] , schema ) =>
444+ some_other_field ? yup . string ( ) . required ( "this is needed" ) : schema
445+ ) ,
446+ docker_config : yup . object ( ) . when ( "type" , {
446447 is : "docker" ,
447448 then : dockerDeploymentSchema ( maxAllowedReplica ) ,
448449 } ) ,
449- standard_config : yup . mixed ( ) . when ( "type" , {
450+ standard_config : yup . object ( ) . when ( "type" , {
450451 is : "standard" ,
451452 then : standardEnsemblerConfigSchema ,
452453 } ) ,
453- pyfunc_config : yup . mixed ( ) . when ( "type" , {
454+ pyfunc_config : yup . object ( ) . when ( "type" , {
454455 is : "pyfunc" ,
455456 then : pyfuncDeploymentSchema ( maxAllowedReplica ) ,
456457 } ) ,
@@ -461,17 +462,17 @@ const schema = (maxAllowedReplica) => [
461462 config : yup . object ( ) . shape ( {
462463 log_config : yup . object ( ) . shape ( {
463464 result_logger_type : yup
464- . mixed ( )
465+ . string ( )
465466 . required ( "Valid Results Logging type should be selected" )
466467 . oneOf (
467468 [ "nop" , "bigquery" , "kafka" ] ,
468469 "Valid Results Logging type should be selected"
469470 ) ,
470- bigquery_config : yup . mixed ( ) . when ( "result_logger_type" , {
471+ bigquery_config : yup . object ( ) . when ( "result_logger_type" , {
471472 is : "bigquery" ,
472473 then : bigQueryConfigSchema ,
473474 } ) ,
474- kafka_config : yup . mixed ( ) . when ( "result_logger_type" , {
475+ kafka_config : yup . object ( ) . when ( "result_logger_type" , {
475476 is : "kafka" ,
476477 then : kafkaConfigSchema ,
477478 } ) ,
0 commit comments