add max-min to schemars (#4005)
Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -51912,12 +51912,16 @@
|
|||||||
"angleEnd": {
|
"angleEnd": {
|
||||||
"description": "The end angle.",
|
"description": "The end angle.",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"format": "double"
|
"format": "double",
|
||||||
|
"maximum": 360.0,
|
||||||
|
"minimum": -360.0
|
||||||
},
|
},
|
||||||
"angleStart": {
|
"angleStart": {
|
||||||
"description": "The start angle.",
|
"description": "The start angle.",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"format": "double"
|
"format": "double",
|
||||||
|
"maximum": 360.0,
|
||||||
|
"minimum": -360.0
|
||||||
},
|
},
|
||||||
"radius": {
|
"radius": {
|
||||||
"description": "The radius.",
|
"description": "The radius.",
|
||||||
@ -221804,6 +221808,8 @@
|
|||||||
"default": null,
|
"default": null,
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"format": "double",
|
"format": "double",
|
||||||
|
"maximum": 360.0,
|
||||||
|
"minimum": -360.0,
|
||||||
"nullable": true
|
"nullable": true
|
||||||
},
|
},
|
||||||
"axis": {
|
"axis": {
|
||||||
|
@ -23,6 +23,7 @@ use crate::{
|
|||||||
pub struct RevolveData {
|
pub struct RevolveData {
|
||||||
/// Angle to revolve (in degrees). Default is 360.
|
/// Angle to revolve (in degrees). Default is 360.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
#[schemars(range(min = -360.0, max = 360.0))]
|
||||||
pub angle: Option<f64>,
|
pub angle: Option<f64>,
|
||||||
/// Axis of revolution.
|
/// Axis of revolution.
|
||||||
pub axis: AxisOrEdgeReference,
|
pub axis: AxisOrEdgeReference,
|
||||||
@ -249,10 +250,12 @@ async fn inner_revolve(
|
|||||||
args: Args,
|
args: Args,
|
||||||
) -> Result<Box<ExtrudeGroup>, KclError> {
|
) -> Result<Box<ExtrudeGroup>, KclError> {
|
||||||
if let Some(angle) = data.angle {
|
if let Some(angle) = data.angle {
|
||||||
// Return an error if the angle is less than -360 or greater than 360.
|
// Return an error if the angle is zero.
|
||||||
if !(-360.0..=360.0).contains(&angle) {
|
// 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 {
|
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],
|
source_ranges: vec![args.source_range],
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -1501,9 +1501,11 @@ pub enum ArcData {
|
|||||||
AnglesAndRadius {
|
AnglesAndRadius {
|
||||||
/// The start angle.
|
/// The start angle.
|
||||||
#[serde(rename = "angleStart", alias = "angle_start")]
|
#[serde(rename = "angleStart", alias = "angle_start")]
|
||||||
|
#[schemars(range(min = -360.0, max = 360.0))]
|
||||||
angle_start: f64,
|
angle_start: f64,
|
||||||
/// The end angle.
|
/// The end angle.
|
||||||
#[serde(rename = "angleEnd", alias = "angle_end")]
|
#[serde(rename = "angleEnd", alias = "angle_end")]
|
||||||
|
#[schemars(range(min = -360.0, max = 360.0))]
|
||||||
angle_end: f64,
|
angle_end: f64,
|
||||||
/// The radius.
|
/// The radius.
|
||||||
radius: f64,
|
radius: f64,
|
||||||
|
@ -951,7 +951,7 @@ async fn kcl_test_revolve_bad_angle_low() {
|
|||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.err().unwrap().to_string(),
|
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!(result.is_err());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.err().unwrap().to_string(),
|
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`" }"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user