diff --git a/kclvm/evaluator/src/schema.rs b/kclvm/evaluator/src/schema.rs index 444b4d0ba..a67d4f368 100644 --- a/kclvm/evaluator/src/schema.rs +++ b/kclvm/evaluator/src/schema.rs @@ -206,11 +206,11 @@ impl SchemaEvalContext { } /// Get all attribute from schema - pub fn get_attrs(s: &Evaluator, ctx: &SchemaEvalContextRef) -> Vec { + pub fn get_attrs(s: &Evaluator, ctx: &SchemaEvalContextRef) -> Vec<(String, bool)> { let mut attrs = vec![]; for stmt in &ctx.borrow().node.body { if let ast::Stmt::SchemaAttr(attr) = &stmt.node { - attrs.push(attr.name.node.clone()); + attrs.push((attr.name.node.clone(), attr.is_optional)); } } if let Some(index) = ctx.borrow().parent { diff --git a/kclvm/evaluator/src/ty.rs b/kclvm/evaluator/src/ty.rs index f9fc8cb32..491be933e 100644 --- a/kclvm/evaluator/src/ty.rs +++ b/kclvm/evaluator/src/ty.rs @@ -124,8 +124,9 @@ pub fn type_pack_and_check( } } - for attr in SchemaEvalContext::get_attrs(s, &caller.ctx) { - if !config.values.contains_key(&attr) { + for (attr, is_optional) in SchemaEvalContext::get_attrs(s, &caller.ctx) + { + if !config.values.contains_key(&attr) && !is_optional { error_msgs .push(format!("Schema {}'s attr {} is missing", tpe, attr)); }