use the jsonschema::RootSchema instead of accidentally inventing our own (#4047)
* updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest)
* empty
* updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
* updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
* fix clippy
Signed-off-by: Jess Frazelle <github@jessfraz.com>
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)
* Revert "A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)"
This reverts commit 64cee26626
.
---------
Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "close"
|
||||
excerpt: "Construct a line segment from the current origin back to the profile's"
|
||||
excerpt: "Construct a line segment from the current origin back to the profile's"
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "e"
|
||||
excerpt: "Return the value of Euler’s number `e`."
|
||||
excerpt: "Return the value of Euler’s number `e`."
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "lastSegX"
|
||||
excerpt: "Extract the 'x' axis value of the last line segment in the provided 2-d"
|
||||
excerpt: "Extract the 'x' axis value of the last line segment in the provided 2-d"
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "lastSegY"
|
||||
excerpt: "Extract the 'y' axis value of the last line segment in the provided 2-d"
|
||||
excerpt: "Extract the 'y' axis value of the last line segment in the provided 2-d"
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "pi"
|
||||
excerpt: "Return the value of `pi`. Archimedes’ constant (π)."
|
||||
excerpt: "Return the value of `pi`. Archimedes’ constant (π)."
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "profileStart"
|
||||
excerpt: "Extract the provided 2-dimensional sketch's profile's origin"
|
||||
excerpt: "Extract the provided 2-dimensional sketch's profile's origin"
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "profileStartX"
|
||||
excerpt: "Extract the provided 2-dimensional sketch's profile's origin's 'x'"
|
||||
excerpt: "Extract the provided 2-dimensional sketch's profile's origin's 'x'"
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "profileStartY"
|
||||
excerpt: "Extract the provided 2-dimensional sketch's profile's origin's 'y'"
|
||||
excerpt: "Extract the provided 2-dimensional sketch's profile's origin's 'y'"
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "rem"
|
||||
excerpt: "Compute the remainder after dividing `num` by `div`."
|
||||
excerpt: "Compute the remainder after dividing `num` by `div`."
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "segEndX"
|
||||
excerpt: "Compute the ending point of the provided line segment along the 'x' axis."
|
||||
excerpt: "Compute the ending point of the provided line segment along the 'x' axis."
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "segEndY"
|
||||
excerpt: "Compute the ending point of the provided line segment along the 'y' axis."
|
||||
excerpt: "Compute the ending point of the provided line segment along the 'y' axis."
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "startSketchAt"
|
||||
excerpt: "Start a new 2-dimensional sketch at a given point on the 'XY' plane."
|
||||
excerpt: "Start a new 2-dimensional sketch at a given point on the 'XY' plane."
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
25303
docs/kcl/std.json
25303
docs/kcl/std.json
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "tangentialArcTo"
|
||||
excerpt: "Starting at the current sketch's origin, draw a curved line segment along"
|
||||
excerpt: "Starting at the current sketch's origin, draw a curved line segment along"
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "tangentialArcToRelative"
|
||||
excerpt: "Starting at the current sketch's origin, draw a curved line segment along"
|
||||
excerpt: "Starting at the current sketch's origin, draw a curved line segment along"
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "tau"
|
||||
excerpt: "Return the value of `tau`. The full circle constant (τ). Equal to 2π."
|
||||
excerpt: "Return the value of `tau`. The full circle constant (τ). Equal to 2π."
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,10 +1,6 @@
|
||||
---
|
||||
title: "Axis"
|
||||
excerpt: "Co-ordinate axis specifier.
|
||||
|
||||
See [cglearn.eu] for background reading.
|
||||
|
||||
[cglearn.eu]: https://cglearn.eu/pub/computer-graphics/introduction-to-geometry#material-coordinate-systems-1"
|
||||
excerpt: "Co-ordinate axis specifier."
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "AxisDirectionPair"
|
||||
excerpt: "An [`Axis`] paired with a [`Direction`]."
|
||||
excerpt: "An [[`Axis`](/docs/kcl/types/Axis)] paired with a [[`Direction`](/docs/kcl/types/Direction)]."
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -28,7 +28,7 @@ A fillet.
|
||||
| `id` |`string`| The id of the engine command that called this fillet. | No |
|
||||
| `radius` |`number`| | No |
|
||||
| `edgeId` |`string`| The engine id of the edge to fillet. | No |
|
||||
| `tag` |[`TagDeclarator`](/docs/kcl/types#tag-declaration)| A fillet or a chamfer. | No |
|
||||
| `tag` |[`TagDeclarator`](/docs/kcl/types#tag-declaration)| | No |
|
||||
|
||||
|
||||
----
|
||||
@ -48,7 +48,7 @@ A chamfer.
|
||||
| `id` |`string`| The id of the engine command that called this chamfer. | No |
|
||||
| `length` |`number`| | No |
|
||||
| `edgeId` |`string`| The engine id of the edge to chamfer. | No |
|
||||
| `tag` |[`TagDeclarator`](/docs/kcl/types#tag-declaration)| A fillet or a chamfer. | No |
|
||||
| `tag` |[`TagDeclarator`](/docs/kcl/types#tag-declaration)| | No |
|
||||
|
||||
|
||||
----
|
||||
|
@ -1,12 +1,6 @@
|
||||
---
|
||||
title: "System"
|
||||
excerpt: "Co-ordinate system definition.
|
||||
|
||||
The `up` axis must be orthogonal to the `forward` axis.
|
||||
|
||||
See [cglearn.eu] for background reading.
|
||||
|
||||
[cglearn.eu](https://cglearn.eu/pub/computer-graphics/introduction-to-geometry#material-coordinate-systems-1)"
|
||||
excerpt: "Co-ordinate system definition."
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -6,12 +6,6 @@ layout: manual
|
||||
|
||||
Data to draw a tangential arc.
|
||||
|
||||
|
||||
|
||||
|
||||
**This schema accepts any of the following:**
|
||||
|
||||
|
||||
**Type:** `object`
|
||||
|
||||
|
||||
@ -26,9 +20,3 @@ Data to draw a tangential arc.
|
||||
| `offset` |`number`| Offset of the arc, in degrees. | No |
|
||||
|
||||
|
||||
----
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
@ -271,24 +271,14 @@ fn do_stdlib_inner(
|
||||
let required = !ty_ident.to_string().starts_with("Option <");
|
||||
|
||||
if ty_string != "ExecState" && ty_string != "Args" {
|
||||
let schema = if ty_ident.to_string().starts_with("Vec < ")
|
||||
|| ty_ident.to_string().starts_with("Option <")
|
||||
|| ty_ident.to_string().starts_with('[')
|
||||
{
|
||||
quote! {
|
||||
<#ty_ident>::json_schema(&mut generator)
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
#ty_ident::json_schema(&mut generator)
|
||||
}
|
||||
let schema = quote! {
|
||||
generator.root_schema_for::<#ty_ident>()
|
||||
};
|
||||
arg_types.push(quote! {
|
||||
#docs_crate::StdLibFnArg {
|
||||
name: #arg_name.to_string(),
|
||||
type_: #ty_string.to_string(),
|
||||
schema: #schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: #required,
|
||||
}
|
||||
});
|
||||
@ -344,12 +334,11 @@ fn do_stdlib_inner(
|
||||
let return_type = if !ret_ty_string.is_empty() || ret_ty_string != "()" {
|
||||
let ret_ty_string = rust_type_to_openapi_type(&ret_ty_string);
|
||||
quote! {
|
||||
let schema = <#return_type_inner>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<#return_type_inner>();
|
||||
Some(#docs_crate::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: #ret_ty_string.to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -81,8 +81,7 @@ impl crate::docs::StdLibFn for SomeFn {
|
||||
vec![crate::docs::StdLibFnArg {
|
||||
name: "data".to_string(),
|
||||
type_: "Foo".to_string(),
|
||||
schema: Foo::json_schema(&mut generator),
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
schema: generator.root_schema_for::<Foo>(),
|
||||
required: true,
|
||||
}]
|
||||
}
|
||||
@ -91,12 +90,11 @@ impl crate::docs::StdLibFn for SomeFn {
|
||||
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
||||
settings.inline_subschemas = inline_subschemas;
|
||||
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
||||
let schema = <i32>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<i32>();
|
||||
Some(crate::docs::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: "i32".to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -81,8 +81,7 @@ impl crate::docs::StdLibFn for SomeFn {
|
||||
vec![crate::docs::StdLibFnArg {
|
||||
name: "data".to_string(),
|
||||
type_: "string".to_string(),
|
||||
schema: str::json_schema(&mut generator),
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
schema: generator.root_schema_for::<str>(),
|
||||
required: true,
|
||||
}]
|
||||
}
|
||||
@ -91,12 +90,11 @@ impl crate::docs::StdLibFn for SomeFn {
|
||||
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
||||
settings.inline_subschemas = inline_subschemas;
|
||||
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
||||
let schema = <i32>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<i32>();
|
||||
Some(crate::docs::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: "i32".to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -114,8 +114,7 @@ impl crate::docs::StdLibFn for Show {
|
||||
vec![crate::docs::StdLibFnArg {
|
||||
name: "args".to_string(),
|
||||
type_: "[number]".to_string(),
|
||||
schema: <[f64; 2usize]>::json_schema(&mut generator),
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
schema: generator.root_schema_for::<[f64; 2usize]>(),
|
||||
required: true,
|
||||
}]
|
||||
}
|
||||
@ -124,12 +123,11 @@ impl crate::docs::StdLibFn for Show {
|
||||
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
||||
settings.inline_subschemas = inline_subschemas;
|
||||
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
||||
let schema = <f64>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<f64>();
|
||||
Some(crate::docs::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: "number".to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -81,8 +81,7 @@ impl crate::docs::StdLibFn for Show {
|
||||
vec![crate::docs::StdLibFnArg {
|
||||
name: "args".to_string(),
|
||||
type_: "number".to_string(),
|
||||
schema: f64::json_schema(&mut generator),
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
schema: generator.root_schema_for::<f64>(),
|
||||
required: true,
|
||||
}]
|
||||
}
|
||||
@ -91,12 +90,11 @@ impl crate::docs::StdLibFn for Show {
|
||||
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
||||
settings.inline_subschemas = inline_subschemas;
|
||||
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
||||
let schema = <f64>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<f64>();
|
||||
Some(crate::docs::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: "number".to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -115,8 +115,7 @@ impl crate::docs::StdLibFn for MyFunc {
|
||||
vec![crate::docs::StdLibFnArg {
|
||||
name: "args".to_string(),
|
||||
type_: "kittycad::types::InputFormat".to_string(),
|
||||
schema: <Option<kittycad::types::InputFormat>>::json_schema(&mut generator),
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
schema: generator.root_schema_for::<Option<kittycad::types::InputFormat>>(),
|
||||
required: false,
|
||||
}]
|
||||
}
|
||||
@ -125,12 +124,11 @@ impl crate::docs::StdLibFn for MyFunc {
|
||||
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
||||
settings.inline_subschemas = inline_subschemas;
|
||||
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
||||
let schema = <Vec<Sketch>>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<Vec<Sketch>>();
|
||||
Some(crate::docs::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: "[Sketch]".to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -116,15 +116,13 @@ impl crate::docs::StdLibFn for LineTo {
|
||||
crate::docs::StdLibFnArg {
|
||||
name: "data".to_string(),
|
||||
type_: "LineToData".to_string(),
|
||||
schema: LineToData::json_schema(&mut generator),
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
schema: generator.root_schema_for::<LineToData>(),
|
||||
required: true,
|
||||
},
|
||||
crate::docs::StdLibFnArg {
|
||||
name: "sketch".to_string(),
|
||||
type_: "Sketch".to_string(),
|
||||
schema: Sketch::json_schema(&mut generator),
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
schema: generator.root_schema_for::<Sketch>(),
|
||||
required: true,
|
||||
},
|
||||
]
|
||||
@ -134,12 +132,11 @@ impl crate::docs::StdLibFn for LineTo {
|
||||
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
||||
settings.inline_subschemas = inline_subschemas;
|
||||
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
||||
let schema = <Sketch>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<Sketch>();
|
||||
Some(crate::docs::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: "Sketch".to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -114,8 +114,7 @@ impl crate::docs::StdLibFn for Min {
|
||||
vec![crate::docs::StdLibFnArg {
|
||||
name: "args".to_string(),
|
||||
type_: "[number]".to_string(),
|
||||
schema: <Vec<f64>>::json_schema(&mut generator),
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
schema: generator.root_schema_for::<Vec<f64>>(),
|
||||
required: true,
|
||||
}]
|
||||
}
|
||||
@ -124,12 +123,11 @@ impl crate::docs::StdLibFn for Min {
|
||||
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
||||
settings.inline_subschemas = inline_subschemas;
|
||||
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
||||
let schema = <f64>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<f64>();
|
||||
Some(crate::docs::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: "number".to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -81,8 +81,7 @@ impl crate::docs::StdLibFn for Show {
|
||||
vec![crate::docs::StdLibFnArg {
|
||||
name: "args".to_string(),
|
||||
type_: "number".to_string(),
|
||||
schema: <Option<f64>>::json_schema(&mut generator),
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
schema: generator.root_schema_for::<Option<f64>>(),
|
||||
required: false,
|
||||
}]
|
||||
}
|
||||
@ -91,12 +90,11 @@ impl crate::docs::StdLibFn for Show {
|
||||
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
||||
settings.inline_subschemas = inline_subschemas;
|
||||
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
||||
let schema = <f64>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<f64>();
|
||||
Some(crate::docs::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: "number".to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -81,8 +81,7 @@ impl crate::docs::StdLibFn for Import {
|
||||
vec![crate::docs::StdLibFnArg {
|
||||
name: "args".to_string(),
|
||||
type_: "kittycad::types::InputFormat".to_string(),
|
||||
schema: <Option<kittycad::types::InputFormat>>::json_schema(&mut generator),
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
schema: generator.root_schema_for::<Option<kittycad::types::InputFormat>>(),
|
||||
required: false,
|
||||
}]
|
||||
}
|
||||
@ -91,12 +90,11 @@ impl crate::docs::StdLibFn for Import {
|
||||
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
||||
settings.inline_subschemas = inline_subschemas;
|
||||
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
||||
let schema = <f64>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<f64>();
|
||||
Some(crate::docs::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: "number".to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -81,8 +81,7 @@ impl crate::docs::StdLibFn for Import {
|
||||
vec![crate::docs::StdLibFnArg {
|
||||
name: "args".to_string(),
|
||||
type_: "kittycad::types::InputFormat".to_string(),
|
||||
schema: <Option<kittycad::types::InputFormat>>::json_schema(&mut generator),
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
schema: generator.root_schema_for::<Option<kittycad::types::InputFormat>>(),
|
||||
required: false,
|
||||
}]
|
||||
}
|
||||
@ -91,12 +90,11 @@ impl crate::docs::StdLibFn for Import {
|
||||
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
||||
settings.inline_subschemas = inline_subschemas;
|
||||
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
||||
let schema = <Vec<Sketch>>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<Vec<Sketch>>();
|
||||
Some(crate::docs::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: "[Sketch]".to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -81,8 +81,7 @@ impl crate::docs::StdLibFn for Import {
|
||||
vec![crate::docs::StdLibFnArg {
|
||||
name: "args".to_string(),
|
||||
type_: "kittycad::types::InputFormat".to_string(),
|
||||
schema: <Option<kittycad::types::InputFormat>>::json_schema(&mut generator),
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
schema: generator.root_schema_for::<Option<kittycad::types::InputFormat>>(),
|
||||
required: false,
|
||||
}]
|
||||
}
|
||||
@ -91,12 +90,11 @@ impl crate::docs::StdLibFn for Import {
|
||||
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
||||
settings.inline_subschemas = inline_subschemas;
|
||||
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
||||
let schema = <Vec<Sketch>>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<Vec<Sketch>>();
|
||||
Some(crate::docs::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: "[Sketch]".to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -81,8 +81,7 @@ impl crate::docs::StdLibFn for Show {
|
||||
vec![crate::docs::StdLibFnArg {
|
||||
name: "args".to_string(),
|
||||
type_: "[number]".to_string(),
|
||||
schema: <Vec<f64>>::json_schema(&mut generator),
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
schema: generator.root_schema_for::<Vec<f64>>(),
|
||||
required: true,
|
||||
}]
|
||||
}
|
||||
@ -91,12 +90,11 @@ impl crate::docs::StdLibFn for Show {
|
||||
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
||||
settings.inline_subschemas = inline_subschemas;
|
||||
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
||||
let schema = <()>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<()>();
|
||||
Some(crate::docs::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: "()".to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -85,12 +85,11 @@ impl crate::docs::StdLibFn for SomeFunction {
|
||||
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
||||
settings.inline_subschemas = inline_subschemas;
|
||||
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
||||
let schema = <i32>::json_schema(&mut generator);
|
||||
let schema = generator.root_schema_for::<i32>();
|
||||
Some(crate::docs::StdLibFnArg {
|
||||
name: "".to_string(),
|
||||
type_: "i32".to_string(),
|
||||
schema,
|
||||
schema_definitions: generator.definitions().clone(),
|
||||
required: true,
|
||||
})
|
||||
}
|
||||
|
@ -234,6 +234,31 @@ fn init_handlebars() -> Result<handlebars::Handlebars<'static>> {
|
||||
),
|
||||
);
|
||||
|
||||
// Register a helper to do safe YAML new lines.
|
||||
hbs.register_helper(
|
||||
"safe_yaml",
|
||||
Box::new(
|
||||
|h: &handlebars::Helper,
|
||||
_: &handlebars::Handlebars,
|
||||
_: &handlebars::Context,
|
||||
_: &mut handlebars::RenderContext,
|
||||
out: &mut dyn handlebars::Output|
|
||||
-> handlebars::HelperResult {
|
||||
if let Some(param) = h.param(0) {
|
||||
if let Some(string) = param.value().as_str() {
|
||||
// Only get the first part before the newline.
|
||||
// This is to prevent the YAML from breaking.
|
||||
let string = string.split('\n').next().unwrap_or("");
|
||||
out.write(string)?;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
out.write("")?;
|
||||
Ok(())
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
hbs.register_template_string("schemaType", include_str!("templates/schemaType.hbs"))?;
|
||||
hbs.register_template_string("properties", include_str!("templates/properties.hbs"))?;
|
||||
hbs.register_template_string("array", include_str!("templates/array.hbs"))?;
|
||||
@ -316,9 +341,9 @@ fn generate_function(internal_fn: Box<dyn StdLibFn>) -> Result<BTreeMap<String,
|
||||
let mut types = BTreeMap::new();
|
||||
for arg in internal_fn.args(false) {
|
||||
if !arg.is_primitive()? {
|
||||
add_to_types(&arg.type_, &arg.schema, &mut types)?;
|
||||
add_to_types(&arg.type_, &arg.schema.schema.into(), &mut types)?;
|
||||
// Add each definition as well.
|
||||
for (name, definition) in &arg.schema_definitions {
|
||||
for (name, definition) in &arg.schema.definitions {
|
||||
add_to_types(name, definition, &mut types)?;
|
||||
}
|
||||
}
|
||||
@ -327,8 +352,8 @@ fn generate_function(internal_fn: Box<dyn StdLibFn>) -> Result<BTreeMap<String,
|
||||
// Generate the type markdown for the return value.
|
||||
if let Some(ret) = internal_fn.return_value(false) {
|
||||
if !ret.is_primitive()? {
|
||||
add_to_types(&ret.type_, &ret.schema, &mut types)?;
|
||||
for (name, definition) in &ret.schema_definitions {
|
||||
add_to_types(&ret.type_, &ret.schema.schema.into(), &mut types)?;
|
||||
for (name, definition) in &ret.schema.definitions {
|
||||
add_to_types(name, definition, &mut types)?;
|
||||
}
|
||||
}
|
||||
@ -674,6 +699,18 @@ fn recurse_and_create_references(
|
||||
if let Some(subschema) = &mut obj.subschemas {
|
||||
// Do anyOf.
|
||||
if let Some(any_of) = &mut subschema.any_of {
|
||||
// If we only have one item in anyOf we can just return that item.
|
||||
if any_of.len() == 1 {
|
||||
let mut new_item = recurse_and_create_references(name, &any_of[0], types)?;
|
||||
if let schemars::schema::Schema::Object(new_obj) = &mut new_item {
|
||||
if let Some(metadata) = new_obj.metadata.as_mut() {
|
||||
metadata.description = obj.metadata.as_ref().and_then(|m| m.description.clone());
|
||||
} else {
|
||||
new_obj.metadata = obj.metadata.clone();
|
||||
}
|
||||
}
|
||||
return Ok(new_item);
|
||||
}
|
||||
for item in any_of {
|
||||
let new_item = recurse_and_create_references(name, item, types)?;
|
||||
*item = new_item;
|
||||
@ -682,6 +719,18 @@ fn recurse_and_create_references(
|
||||
|
||||
// Do allOf.
|
||||
if let Some(all_of) = &mut subschema.all_of {
|
||||
// If we only have one item in allOf we can just return that item.
|
||||
if all_of.len() == 1 {
|
||||
let mut new_item = recurse_and_create_references(name, &all_of[0], types)?;
|
||||
if let schemars::schema::Schema::Object(new_obj) = &mut new_item {
|
||||
if let Some(metadata) = new_obj.metadata.as_mut() {
|
||||
metadata.description = obj.metadata.as_ref().and_then(|m| m.description.clone());
|
||||
} else {
|
||||
new_obj.metadata = obj.metadata.clone();
|
||||
}
|
||||
}
|
||||
return Ok(new_item);
|
||||
}
|
||||
for item in all_of {
|
||||
let new_item = recurse_and_create_references(name, item, types)?;
|
||||
*item = new_item;
|
||||
@ -690,6 +739,18 @@ fn recurse_and_create_references(
|
||||
|
||||
// Do oneOf.
|
||||
if let Some(one_of) = &mut subschema.one_of {
|
||||
// If we only have one item in oneOf we can just return that item.
|
||||
if one_of.len() == 1 {
|
||||
let mut new_item = recurse_and_create_references(name, &one_of[0], types)?;
|
||||
if let schemars::schema::Schema::Object(new_obj) = &mut new_item {
|
||||
if let Some(metadata) = new_obj.metadata.as_mut() {
|
||||
metadata.description = obj.metadata.as_ref().and_then(|m| m.description.clone());
|
||||
} else {
|
||||
new_obj.metadata = obj.metadata.clone();
|
||||
}
|
||||
}
|
||||
return Ok(new_item);
|
||||
}
|
||||
for item in one_of {
|
||||
let new_item = recurse_and_create_references(name, item, types)?;
|
||||
*item = new_item;
|
||||
|
@ -52,10 +52,7 @@ pub struct StdLibFnArg {
|
||||
pub type_: String,
|
||||
/// The schema of the argument.
|
||||
#[ts(type = "any")]
|
||||
pub schema: schemars::schema::Schema,
|
||||
/// The schema definitions for the argument.
|
||||
#[ts(type = "any")]
|
||||
pub schema_definitions: schemars::Map<String, schemars::schema::Schema>,
|
||||
pub schema: schemars::schema::RootSchema,
|
||||
/// If the argument is required.
|
||||
pub required: bool,
|
||||
}
|
||||
@ -63,11 +60,11 @@ pub struct StdLibFnArg {
|
||||
impl StdLibFnArg {
|
||||
/// If the argument is a primitive.
|
||||
pub fn is_primitive(&self) -> Result<bool> {
|
||||
is_primitive(&self.schema).map(|r| r.is_some())
|
||||
is_primitive(&self.schema.schema.clone().into()).map(|r| r.is_some())
|
||||
}
|
||||
|
||||
pub fn get_autocomplete_string(&self) -> Result<String> {
|
||||
get_autocomplete_string_from_schema(&self.schema.clone())
|
||||
get_autocomplete_string_from_schema(&self.schema.schema.clone().into())
|
||||
}
|
||||
|
||||
pub fn get_autocomplete_snippet(&self, index: usize) -> Result<Option<(usize, String)>> {
|
||||
@ -85,11 +82,11 @@ impl StdLibFnArg {
|
||||
// TODO: actually use the ast to populate this.
|
||||
return Ok(Some((index, format!("${{{}:{}}}", index, "myTag"))));
|
||||
}
|
||||
get_autocomplete_snippet_from_schema(&self.schema.clone(), index)
|
||||
get_autocomplete_snippet_from_schema(&self.schema.schema.clone().into(), index)
|
||||
}
|
||||
|
||||
pub fn description(&self) -> Option<String> {
|
||||
get_description_string_from_schema(&self.schema.clone(), &self.schema_definitions)
|
||||
get_description_string_from_schema(&self.schema.clone())
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,20 +308,55 @@ impl Clone for Box<dyn StdLibFn> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_description_string_from_schema(
|
||||
schema: &schemars::schema::Schema,
|
||||
definitions: &schemars::Map<String, schemars::schema::Schema>,
|
||||
) -> Option<String> {
|
||||
if let schemars::schema::Schema::Object(o) = schema {
|
||||
if let Some(metadata) = &o.metadata {
|
||||
pub fn get_description_string_from_schema(schema: &schemars::schema::RootSchema) -> Option<String> {
|
||||
if let Some(metadata) = &schema.schema.metadata {
|
||||
if let Some(description) = &metadata.description {
|
||||
return Some(description.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(reference) = &o.reference {
|
||||
if let Some(definition) = definitions.get(reference.split('/').last().unwrap_or("")) {
|
||||
return get_description_string_from_schema(definition, definitions);
|
||||
if let Some(reference) = &schema.schema.reference {
|
||||
if let Some(definition) = schema.definitions.get(reference.split('/').last().unwrap_or("")) {
|
||||
let schemars::schema::Schema::Object(definition) = definition else {
|
||||
return None;
|
||||
};
|
||||
if let Some(metadata) = &definition.metadata {
|
||||
if let Some(description) = &metadata.description {
|
||||
return Some(description.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we have subschemas iterate over them and recursively create references.
|
||||
if let Some(subschema) = &schema.schema.subschemas {
|
||||
if let Some(one_of) = &subschema.one_of {
|
||||
if one_of.len() == 1 {
|
||||
return get_description_string_from_schema(&schemars::schema::RootSchema {
|
||||
meta_schema: schema.meta_schema.clone(),
|
||||
schema: one_of[0].clone().into(),
|
||||
definitions: schema.definitions.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(all_of) = &subschema.all_of {
|
||||
if all_of.len() == 1 {
|
||||
return get_description_string_from_schema(&schemars::schema::RootSchema {
|
||||
meta_schema: schema.meta_schema.clone(),
|
||||
schema: all_of[0].clone().into(),
|
||||
definitions: schema.definitions.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(any_of) = &subschema.any_of {
|
||||
if any_of.len() == 1 {
|
||||
return get_description_string_from_schema(&schemars::schema::RootSchema {
|
||||
meta_schema: schema.meta_schema.clone(),
|
||||
schema: any_of[0].clone().into(),
|
||||
definitions: schema.definitions.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -704,10 +736,14 @@ pub fn completion_item_from_enum_schema(
|
||||
kind: CompletionItemKind,
|
||||
) -> Result<CompletionItem> {
|
||||
// Get the docs for the schema.
|
||||
let description = get_description_string_from_schema(schema, &Default::default()).unwrap_or_default();
|
||||
let schemars::schema::Schema::Object(o) = schema else {
|
||||
anyhow::bail!("expected object schema: {:#?}", schema);
|
||||
};
|
||||
let description = get_description_string_from_schema(&schemars::schema::RootSchema {
|
||||
schema: o.clone(),
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let Some(enum_values) = o.enum_values.as_ref() else {
|
||||
anyhow::bail!("expected enum values: {:#?}", o);
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "{{name}}"
|
||||
excerpt: "{{summary}}"
|
||||
excerpt: "{{safe_yaml summary}}"
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
2
src/wasm-lib/kcl/src/docs/templates/type.hbs
vendored
2
src/wasm-lib/kcl/src/docs/templates/type.hbs
vendored
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "{{title}}"
|
||||
excerpt: "{{description}}"
|
||||
excerpt: "{{safe_yaml description}}"
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
use derive_docs::stdlib;
|
||||
use schemars::JsonSchema;
|
||||
|
||||
use super::{args::FromArgs, Args, FnAsArg};
|
||||
use crate::{
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
use anyhow::Result;
|
||||
use derive_docs::stdlib;
|
||||
use schemars::JsonSchema;
|
||||
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
|
@ -1,7 +1,6 @@
|
||||
//! Conversions between types.
|
||||
|
||||
use derive_docs::stdlib;
|
||||
use schemars::JsonSchema;
|
||||
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
|
@ -9,7 +9,6 @@ use kcmc::{
|
||||
shared::ExtrusionFaceCapType, websocket::OkWebSocketResponseData, ModelingCmd,
|
||||
};
|
||||
use kittycad_modeling_cmds as kcmc;
|
||||
use schemars::JsonSchema;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
|
@ -15,7 +15,6 @@ use kcmc::{
|
||||
ImportFile, ModelingCmd,
|
||||
};
|
||||
use kittycad_modeling_cmds as kcmc;
|
||||
use schemars::JsonSchema;
|
||||
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
use anyhow::Result;
|
||||
use derive_docs::stdlib;
|
||||
use schemars::JsonSchema;
|
||||
|
||||
use super::args::FromArgs;
|
||||
use crate::{
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
use anyhow::Result;
|
||||
use derive_docs::stdlib;
|
||||
use schemars::JsonSchema;
|
||||
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
use anyhow::Result;
|
||||
use derive_docs::stdlib;
|
||||
use schemars::JsonSchema;
|
||||
|
||||
use crate::{
|
||||
errors::KclError,
|
||||
|
Reference in New Issue
Block a user