SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Agents and scripts: Parameter Sweep's schema requires its parameter, as text (#12312)
austin62jake3d7382244273
diff --git a/crates/engine/src/schema/parameter_sweep.rs b/crates/engine/src/schema/parameter_sweep.rsindex afd5e0ad2e..7f39f58901 100644--- a/crates/engine/src/schema/parameter_sweep.rs+++ b/crates/engine/src/schema/parameter_sweep.rs@@ -17,11 +17,13 @@ pub const MAX_VALUES: usize = 200;/// or loses its reference there, against the design as it is. The design itself isn't changed./// Give `values`, or `from` and `to`.#[derive(Debug, Deserialize, JsonSchema)]-#[schemars(deny_unknown_fields)]+#[schemars(deny_unknown_fields, transform = parameter_required)]pub struct ParameterSweepParams {/// The parameter, by name, as `parameters.list` lists it.+ // Optional in the type, required in the schema (`parameter_required`): left out, the+ // handler refuses the call with its own message. Text only, as `parameter_name` reads it.#[serde(default, deserialize_with = "parameter_name")]- #[schemars(required, transform = drop_default)]+ #[schemars(with = "String", transform = drop_default)]pub parameter: Option<String>,#[serde(default, deserialize_with = "present")]#[schemars(with = "SweepValues")]@@ -45,6 +47,22 @@ fn drop_default(schema: &mut Schema) {schema.remove("default");}+/// Puts `parameter` in the schema's `required` list. The type has it optional so that the+/// handler, not the check, refuses a call without it, with its own message; a field's+/// `#[schemars(required)]` doesn't do this for a key with `serde(default)`.+fn parameter_required(schema: &mut Schema) {+ match schema.get_mut("required") {+ Some(Value::Array(required)) => {+ if !required.iter().any(|k| k == "parameter") {+ required.push("parameter".into());+ }+ }+ _ => {+ schema.insert("required".into(), Value::Array(vec!["parameter".into()]));+ }+ }+}+/// The parameter's name, with the handler's message for anything that isn't text.fn parameter_name<'de, D: Deserializer<'de>>(d: D) -> Result<Option<String>, D::Error> {match Value::deserialize(d)? {diff --git a/crates/engine/src/schema/parameter_sweep_tests.rs b/crates/engine/src/schema/parameter_sweep_tests.rsindex 3f2b3027f4..fe13007b34 100644--- a/crates/engine/src/schema/parameter_sweep_tests.rs+++ b/crates/engine/src/schema/parameter_sweep_tests.rs@@ -32,6 +32,22 @@ fn schemas_and_the_key_check_agree() {assert_keys(input_schema_for::<ParameterSweepParams>(), &["from", "parameter", "steps", "to", "values"]);}+/// The schema requires `parameter`, as text, as the handler does: left out, `null` or a number,+/// the handler refuses the call ("`parameter` is required"), so the schema refuses it too.+#[test]+fn the_schema_requires_the_parameter_as_text() {+ let schema = input_schema_for::<ParameterSweepParams>();+ let schema = schema.as_value();+ for (p, takes) in [+ (json!({"parameter": "w", "values": [1, 2]}), true),+ (json!({"values": [1, 2]}), false),+ (json!({"parameter": null, "values": [1, 2]}), false),+ (json!({"parameter": 5, "values": [1, 2]}), false),+ ] {+ assert_eq!(conforms(schema, schema, &p), takes, "{p}");+ }+}+/// A call that fails today gets the same message in strict. The handler looks the parameter up/// before it reads the values, so each call runs on a design that has one/// (`assert_strict_keeps_todays_errors` runs on one that has none).