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:
Jess Frazelle
2024-09-30 12:30:22 -07:00
committed by GitHub
parent bb3f9e0377
commit f74b436e3d
48 changed files with 132559 additions and 112098 deletions

View File

@ -1,6 +1,6 @@
---
title: "close"
excerpt: "Construct a line segment from the current origin back to the profile&#x27;s"
excerpt: "Construct a line segment from the current origin back to the profile's"
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "e"
excerpt: "Return the value of Eulers number &#x60;e&#x60;."
excerpt: "Return the value of Eulers number `e`."
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "lastSegX"
excerpt: "Extract the &#x27;x&#x27; 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
---

View File

@ -1,6 +1,6 @@
---
title: "lastSegY"
excerpt: "Extract the &#x27;y&#x27; 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
---

View File

@ -1,6 +1,6 @@
---
title: "pi"
excerpt: "Return the value of &#x60;pi&#x60;. Archimedes constant (π)."
excerpt: "Return the value of `pi`. Archimedes constant (π)."
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "profileStart"
excerpt: "Extract the provided 2-dimensional sketch&#x27;s profile&#x27;s origin"
excerpt: "Extract the provided 2-dimensional sketch's profile's origin"
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "profileStartX"
excerpt: "Extract the provided 2-dimensional sketch&#x27;s profile&#x27;s origin&#x27;s &#x27;x&#x27;"
excerpt: "Extract the provided 2-dimensional sketch's profile's origin's 'x'"
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "profileStartY"
excerpt: "Extract the provided 2-dimensional sketch&#x27;s profile&#x27;s origin&#x27;s &#x27;y&#x27;"
excerpt: "Extract the provided 2-dimensional sketch's profile's origin's 'y'"
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "rem"
excerpt: "Compute the remainder after dividing &#x60;num&#x60; by &#x60;div&#x60;."
excerpt: "Compute the remainder after dividing `num` by `div`."
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "segEndX"
excerpt: "Compute the ending point of the provided line segment along the &#x27;x&#x27; axis."
excerpt: "Compute the ending point of the provided line segment along the 'x' axis."
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "segEndY"
excerpt: "Compute the ending point of the provided line segment along the &#x27;y&#x27; axis."
excerpt: "Compute the ending point of the provided line segment along the 'y' axis."
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "startSketchAt"
excerpt: "Start a new 2-dimensional sketch at a given point on the &#x27;XY&#x27; plane."
excerpt: "Start a new 2-dimensional sketch at a given point on the 'XY' plane."
layout: manual
---

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
---
title: "tangentialArcTo"
excerpt: "Starting at the current sketch&#x27;s origin, draw a curved line segment along"
excerpt: "Starting at the current sketch's origin, draw a curved line segment along"
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "tangentialArcToRelative"
excerpt: "Starting at the current sketch&#x27;s origin, draw a curved line segment along"
excerpt: "Starting at the current sketch's origin, draw a curved line segment along"
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "tau"
excerpt: "Return the value of &#x60;tau&#x60;. The full circle constant (τ). Equal to 2π."
excerpt: "Return the value of `tau`. The full circle constant (τ). Equal to 2π."
layout: manual
---

View File

@ -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
---

View File

@ -1,6 +1,6 @@
---
title: "AxisDirectionPair"
excerpt: "An [&#x60;Axis&#x60;] paired with a [&#x60;Direction&#x60;]."
excerpt: "An [[`Axis`](/docs/kcl/types/Axis)] paired with a [[`Direction`](/docs/kcl/types/Direction)]."
layout: manual
---

View File

@ -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 |
----

View File

@ -1,12 +1,6 @@
---
title: "System"
excerpt: "Co-ordinate system definition.
The &#x60;up&#x60; axis must be orthogonal to the &#x60;forward&#x60; 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
---

View File

@ -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

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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;

View File

@ -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);
};

View File

@ -1,6 +1,6 @@
---
title: "{{name}}"
excerpt: "{{summary}}"
excerpt: "{{safe_yaml summary}}"
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "{{title}}"
excerpt: "{{description}}"
excerpt: "{{safe_yaml description}}"
layout: manual
---

View File

@ -1,5 +1,4 @@
use derive_docs::stdlib;
use schemars::JsonSchema;
use super::{args::FromArgs, Args, FnAsArg};
use crate::{

View File

@ -2,7 +2,6 @@
use anyhow::Result;
use derive_docs::stdlib;
use schemars::JsonSchema;
use crate::{
errors::{KclError, KclErrorDetails},

View File

@ -1,7 +1,6 @@
//! Conversions between types.
use derive_docs::stdlib;
use schemars::JsonSchema;
use crate::{
errors::{KclError, KclErrorDetails},

View File

@ -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::{

View File

@ -15,7 +15,6 @@ use kcmc::{
ImportFile, ModelingCmd,
};
use kittycad_modeling_cmds as kcmc;
use schemars::JsonSchema;
use crate::{
errors::{KclError, KclErrorDetails},

View File

@ -2,7 +2,6 @@
use anyhow::Result;
use derive_docs::stdlib;
use schemars::JsonSchema;
use super::args::FromArgs;
use crate::{

View File

@ -2,7 +2,6 @@
use anyhow::Result;
use derive_docs::stdlib;
use schemars::JsonSchema;
use crate::{
errors::{KclError, KclErrorDetails},

View File

@ -2,7 +2,6 @@
use anyhow::Result;
use derive_docs::stdlib;
use schemars::JsonSchema;
use crate::{
errors::KclError,