diff --git a/docs/kcl/std.json b/docs/kcl/std.json index 41772dfcd..74ca8918a 100644 --- a/docs/kcl/std.json +++ b/docs/kcl/std.json @@ -51912,12 +51912,16 @@ "angleEnd": { "description": "The end angle.", "type": "number", - "format": "double" + "format": "double", + "maximum": 360.0, + "minimum": -360.0 }, "angleStart": { "description": "The start angle.", "type": "number", - "format": "double" + "format": "double", + "maximum": 360.0, + "minimum": -360.0 }, "radius": { "description": "The radius.", @@ -221804,6 +221808,8 @@ "default": null, "type": "number", "format": "double", + "maximum": 360.0, + "minimum": -360.0, "nullable": true }, "axis": { diff --git a/src/wasm-lib/kcl/src/std/revolve.rs b/src/wasm-lib/kcl/src/std/revolve.rs index 5a28caf63..8edc22098 100644 --- a/src/wasm-lib/kcl/src/std/revolve.rs +++ b/src/wasm-lib/kcl/src/std/revolve.rs @@ -23,6 +23,7 @@ use crate::{ pub struct RevolveData { /// Angle to revolve (in degrees). Default is 360. #[serde(default)] + #[schemars(range(min = -360.0, max = 360.0))] pub angle: Option, /// Axis of revolution. pub axis: AxisOrEdgeReference, @@ -249,10 +250,12 @@ async fn inner_revolve( args: Args, ) -> Result, KclError> { if let Some(angle) = data.angle { - // Return an error if the angle is less than -360 or greater than 360. - if !(-360.0..=360.0).contains(&angle) { + // Return an error if the angle is zero. + // We don't use validate() here because we want to return a specific error message that is + // nice and we use the other data in the docs, so we still need use the derive above for the json schema. + if !(-360.0..=360.0).contains(&angle) || angle == 0.0 { return Err(KclError::Semantic(KclErrorDetails { - message: format!("Expected angle to be between -360 and 360, found `{}`", angle), + message: format!("Expected angle to be between -360 and 360 and not 0, found `{}`", angle), source_ranges: vec![args.source_range], })); } diff --git a/src/wasm-lib/kcl/src/std/sketch.rs b/src/wasm-lib/kcl/src/std/sketch.rs index 18e226ac0..ace9493d3 100644 --- a/src/wasm-lib/kcl/src/std/sketch.rs +++ b/src/wasm-lib/kcl/src/std/sketch.rs @@ -1501,9 +1501,11 @@ pub enum ArcData { AnglesAndRadius { /// The start angle. #[serde(rename = "angleStart", alias = "angle_start")] + #[schemars(range(min = -360.0, max = 360.0))] angle_start: f64, /// The end angle. #[serde(rename = "angleEnd", alias = "angle_end")] + #[schemars(range(min = -360.0, max = 360.0))] angle_end: f64, /// The radius. radius: f64, diff --git a/src/wasm-lib/tests/executor/main.rs b/src/wasm-lib/tests/executor/main.rs index cedcd01e6..14c7ea0c7 100644 --- a/src/wasm-lib/tests/executor/main.rs +++ b/src/wasm-lib/tests/executor/main.rs @@ -951,7 +951,7 @@ async fn kcl_test_revolve_bad_angle_low() { assert!(result.is_err()); assert_eq!( result.err().unwrap().to_string(), - r#"semantic: KclErrorDetails { source_ranges: [SourceRange([278, 314])], message: "Expected angle to be between -360 and 360, found `-455`" }"# + r#"semantic: KclErrorDetails { source_ranges: [SourceRange([278, 314])], message: "Expected angle to be between -360 and 360 and not 0, found `-455`" }"# ); } @@ -976,7 +976,7 @@ async fn kcl_test_revolve_bad_angle_high() { assert!(result.is_err()); assert_eq!( result.err().unwrap().to_string(), - r#"semantic: KclErrorDetails { source_ranges: [SourceRange([278, 313])], message: "Expected angle to be between -360 and 360, found `455`" }"# + r#"semantic: KclErrorDetails { source_ranges: [SourceRange([278, 313])], message: "Expected angle to be between -360 and 360 and not 0, found `455`" }"# ); }