breaking change: Change "type" to be a keyword, import() "type:" parameter to "format:" (#4517)

This commit is contained in:
Jonathan Tran
2024-11-20 09:53:37 -05:00
committed by GitHub
parent 986675fe89
commit a2f9e70d18
8 changed files with 31 additions and 30 deletions

File diff suppressed because one or more lines are too long

View File

@ -78138,10 +78138,10 @@
"description": "Autodesk Filmbox (FBX) format", "description": "Autodesk Filmbox (FBX) format",
"type": "object", "type": "object",
"required": [ "required": [
"type" "format"
], ],
"properties": { "properties": {
"type": { "format": {
"type": "string", "type": "string",
"enum": [ "enum": [
"fbx" "fbx"
@ -78153,10 +78153,10 @@
"description": "Binary glTF 2.0. We refer to this as glTF since that is how our customers refer to it, but this can also import binary glTF (glb).", "description": "Binary glTF 2.0. We refer to this as glTF since that is how our customers refer to it, but this can also import binary glTF (glb).",
"type": "object", "type": "object",
"required": [ "required": [
"type" "format"
], ],
"properties": { "properties": {
"type": { "format": {
"type": "string", "type": "string",
"enum": [ "enum": [
"gltf" "gltf"
@ -78168,11 +78168,11 @@
"description": "Wavefront OBJ format.", "description": "Wavefront OBJ format.",
"type": "object", "type": "object",
"required": [ "required": [
"type", "format",
"units" "units"
], ],
"properties": { "properties": {
"type": { "format": {
"type": "string", "type": "string",
"enum": [ "enum": [
"obj" "obj"
@ -78201,11 +78201,11 @@
"description": "The PLY Polygon File Format.", "description": "The PLY Polygon File Format.",
"type": "object", "type": "object",
"required": [ "required": [
"type", "format",
"units" "units"
], ],
"properties": { "properties": {
"type": { "format": {
"type": "string", "type": "string",
"enum": [ "enum": [
"ply" "ply"
@ -78234,10 +78234,10 @@
"description": "SolidWorks part (SLDPRT) format.", "description": "SolidWorks part (SLDPRT) format.",
"type": "object", "type": "object",
"required": [ "required": [
"type" "format"
], ],
"properties": { "properties": {
"type": { "format": {
"type": "string", "type": "string",
"enum": [ "enum": [
"sldprt" "sldprt"
@ -78249,10 +78249,10 @@
"description": "ISO 10303-21 (STEP) format.", "description": "ISO 10303-21 (STEP) format.",
"type": "object", "type": "object",
"required": [ "required": [
"type" "format"
], ],
"properties": { "properties": {
"type": { "format": {
"type": "string", "type": "string",
"enum": [ "enum": [
"step" "step"
@ -78264,11 +78264,11 @@
"description": "ST**ereo**L**ithography format.", "description": "ST**ereo**L**ithography format.",
"type": "object", "type": "object",
"required": [ "required": [
"type", "format",
"units" "units"
], ],
"properties": { "properties": {
"type": { "format": {
"type": "string", "type": "string",
"enum": [ "enum": [
"stl" "stl"
@ -78506,7 +78506,7 @@
"deprecated": false, "deprecated": false,
"examples": [ "examples": [
"model = import(\"tests/inputs/cube.obj\")", "model = import(\"tests/inputs/cube.obj\")",
"model = import(\"tests/inputs/cube.obj\", { type: \"obj\", units: \"m\" })", "model = import(\"tests/inputs/cube.obj\", { format: \"obj\", units: \"m\" })",
"model = import(\"tests/inputs/cube.gltf\")", "model = import(\"tests/inputs/cube.gltf\")",
"model = import(\"tests/inputs/cube.sldprt\")", "model = import(\"tests/inputs/cube.sldprt\")",
"model = import(\"tests/inputs/cube.step\")", "model = import(\"tests/inputs/cube.step\")",

View File

@ -24,7 +24,7 @@ Autodesk Filmbox (FBX) format
| Property | Type | Description | Required | | Property | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `type` |enum: `fbx`| | No | | `format` |enum: `fbx`| | No |
---- ----
@ -40,7 +40,7 @@ Binary glTF 2.0. We refer to this as glTF since that is how our customers refer
| Property | Type | Description | Required | | Property | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `type` |enum: `gltf`| | No | | `format` |enum: `gltf`| | No |
---- ----
@ -56,7 +56,7 @@ Wavefront OBJ format.
| Property | Type | Description | Required | | Property | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `type` |enum: `obj`| | No | | `format` |enum: `obj`| | No |
| `coords` |[`System`](/docs/kcl/types/System)| Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system. | No | | `coords` |[`System`](/docs/kcl/types/System)| Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system. | No |
| `units` |[`UnitLength`](/docs/kcl/types/UnitLength)| The units of the input data. This is very important for correct scaling and when calculating physics properties like mass, etc. Defaults to millimeters. | No | | `units` |[`UnitLength`](/docs/kcl/types/UnitLength)| The units of the input data. This is very important for correct scaling and when calculating physics properties like mass, etc. Defaults to millimeters. | No |
@ -74,7 +74,7 @@ The PLY Polygon File Format.
| Property | Type | Description | Required | | Property | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `type` |enum: `ply`| | No | | `format` |enum: `ply`| | No |
| `coords` |[`System`](/docs/kcl/types/System)| Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system. | No | | `coords` |[`System`](/docs/kcl/types/System)| Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system. | No |
| `units` |[`UnitLength`](/docs/kcl/types/UnitLength)| The units of the input data. This is very important for correct scaling and when calculating physics properties like mass, etc. Defaults to millimeters. | No | | `units` |[`UnitLength`](/docs/kcl/types/UnitLength)| The units of the input data. This is very important for correct scaling and when calculating physics properties like mass, etc. Defaults to millimeters. | No |
@ -92,7 +92,7 @@ SolidWorks part (SLDPRT) format.
| Property | Type | Description | Required | | Property | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `type` |enum: `sldprt`| | No | | `format` |enum: `sldprt`| | No |
---- ----
@ -108,7 +108,7 @@ ISO 10303-21 (STEP) format.
| Property | Type | Description | Required | | Property | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `type` |enum: `step`| | No | | `format` |enum: `step`| | No |
---- ----
@ -124,7 +124,7 @@ ST**ereo**L**ithography format.
| Property | Type | Description | Required | | Property | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `type` |enum: `stl`| | No | | `format` |enum: `stl`| | No |
| `coords` |[`System`](/docs/kcl/types/System)| Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system. | No | | `coords` |[`System`](/docs/kcl/types/System)| Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system. | No |
| `units` |[`UnitLength`](/docs/kcl/types/UnitLength)| The units of the input data. This is very important for correct scaling and when calculating physics properties like mass, etc. Defaults to millimeters. | No | | `units` |[`UnitLength`](/docs/kcl/types/UnitLength)| The units of the input data. This is very important for correct scaling and when calculating physics properties like mass, etc. Defaults to millimeters. | No |

View File

@ -692,7 +692,7 @@ macro_rules! let_field_of {
impl<'a> FromKclValue<'a> for crate::std::import::ImportFormat { impl<'a> FromKclValue<'a> for crate::std::import::ImportFormat {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> { fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
let obj = arg.as_object()?; let obj = arg.as_object()?;
let_field_of!(obj, typ "type"); let_field_of!(obj, typ "format");
match typ { match typ {
"fbx" => Some(Self::Fbx {}), "fbx" => Some(Self::Fbx {}),
"gltf" => Some(Self::Gltf {}), "gltf" => Some(Self::Gltf {}),

View File

@ -42,7 +42,7 @@ const ZOO_COORD_SYSTEM: System = System {
/// Import format specifier /// Import format specifier
#[derive(serde :: Serialize, serde :: Deserialize, PartialEq, Debug, Clone, schemars :: JsonSchema)] #[derive(serde :: Serialize, serde :: Deserialize, PartialEq, Debug, Clone, schemars :: JsonSchema)]
#[cfg_attr(feature = "tabled", derive(tabled::Tabled))] #[cfg_attr(feature = "tabled", derive(tabled::Tabled))]
#[serde(tag = "type")] #[serde(tag = "format")]
pub enum ImportFormat { pub enum ImportFormat {
/// Autodesk Filmbox (FBX) format /// Autodesk Filmbox (FBX) format
#[serde(rename = "fbx")] #[serde(rename = "fbx")]
@ -152,7 +152,7 @@ pub async fn import(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// ``` /// ```
/// ///
/// ```no_run /// ```no_run
/// const model = import("tests/inputs/cube.obj", {type: "obj", units: "m"}) /// const model = import("tests/inputs/cube.obj", {format: "obj", units: "m"})
/// ``` /// ```
/// ///
/// ```no_run /// ```no_run

View File

@ -42,6 +42,7 @@ lazy_static! {
set.insert("const", TokenType::Keyword); set.insert("const", TokenType::Keyword);
// "import" is special because of import(). // "import" is special because of import().
set.insert("export", TokenType::Keyword); set.insert("export", TokenType::Keyword);
set.insert("type", TokenType::Keyword);
set.insert("interface", TokenType::Keyword); set.insert("interface", TokenType::Keyword);
set.insert("new", TokenType::Keyword); set.insert("new", TokenType::Keyword);
set.insert("self", TokenType::Keyword); set.insert("self", TokenType::Keyword);

View File

@ -1685,7 +1685,7 @@ things = "things"
let some_program_string = r#"b = { let some_program_string = r#"b = {
end: 141, end: 141,
start: 125, start: 125,
type: "NonCodeNode", type_: "NonCodeNode",
value: " value: "
// a comment // a comment
" "

View File

@ -526,7 +526,7 @@ async fn kcl_test_import_obj_with_mtl() {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_import_obj_with_mtl_units() { async fn kcl_test_import_obj_with_mtl_units() {
let code = r#"model = import("tests/executor/inputs/cube.obj", {type: "obj", units: "m"})"#; let code = r#"model = import("tests/executor/inputs/cube.obj", {format: "obj", units: "m"})"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("import_obj_with_mtl_units", &result); assert_out("import_obj_with_mtl_units", &result);
@ -574,13 +574,13 @@ async fn kcl_test_import_glb_no_assign() {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_import_ext_doesnt_match() { async fn kcl_test_import_ext_doesnt_match() {
let code = r#"model = import("tests/executor/inputs/cube.gltf", {type: "obj", units: "m"})"#; let code = r#"model = import("tests/executor/inputs/cube.gltf", {format: "obj", units: "m"})"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await; let result = execute_and_snapshot(code, UnitLength::Mm).await;
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([8, 76, 0])], message: "The given format does not match the file extension. Expected: `gltf`, Given: `obj`" }"# r#"semantic: KclErrorDetails { source_ranges: [SourceRange([8, 78, 0])], message: "The given format does not match the file extension. Expected: `gltf`, Given: `obj`" }"#
); );
} }