Skip to content

Commit

Permalink
Fix docs/json/snippets generation from schemas
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Cameron <[email protected]>
  • Loading branch information
nrc committed Feb 19, 2025
1 parent 3181bca commit 9ca6727
Show file tree
Hide file tree
Showing 75 changed files with 43,437 additions and 20,859 deletions.
44,228 changes: 27,075 additions & 17,153 deletions docs/kcl/std.json

Large diffs are not rendered by default.

24 changes: 21 additions & 3 deletions src/components/ModelingSidebar/ModelingPanes/MemoryPane.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,27 @@ describe('processMemory', () => {
},
],
theSketch: [
{ type: 'ToPoint', to: [-3.35, 0.17], from: [0, 0], tag: null },
{ type: 'ToPoint', to: [0.98, 5.16], from: [-3.35, 0.17], tag: null },
{ type: 'ToPoint', to: [2.15, 4.32], from: [0.98, 5.16], tag: null },
{
type: 'ToPoint',
to: [-3.35, 0.17],
from: [0, 0],
units: { type: 'Mm' },
tag: null,
},
{
type: 'ToPoint',
to: [0.98, 5.16],
from: [-3.35, 0.17],
units: { type: 'Mm' },
tag: null,
},
{
type: 'ToPoint',
to: [2.15, 4.32],
from: [0.98, 5.16],
units: { type: 'Mm' },
tag: null,
},
],
})
})
Expand Down
11 changes: 11 additions & 0 deletions src/lang/artifact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const mySketch001 = startSketchOn('XY')
start: {
to: [0, 0],
from: [0, 0],
units: { type: 'Mm' },
tag: null,
__geoMeta: {
id: expect.any(String),
Expand All @@ -35,6 +36,7 @@ const mySketch001 = startSketchOn('XY')
type: 'ToPoint',
tag: null,
to: [-1.59, -1.54],
units: { type: 'Mm' },
from: [0, 0],
__geoMeta: {
sourceRange: [expect.any(Number), expect.any(Number), 0],
Expand All @@ -45,6 +47,7 @@ const mySketch001 = startSketchOn('XY')
type: 'ToPoint',
to: [0.46, -5.82],
from: [-1.59, -1.54],
units: { type: 'Mm' },
tag: null,
__geoMeta: {
sourceRange: [expect.any(Number), expect.any(Number), 0],
Expand Down Expand Up @@ -111,6 +114,7 @@ const mySketch001 = startSketchOn('XY')
type: 'ToPoint',
from: [0, 0],
to: [-1.59, -1.54],
units: { type: 'Mm' },
tag: null,
__geoMeta: {
id: expect.any(String),
Expand All @@ -121,6 +125,7 @@ const mySketch001 = startSketchOn('XY')
type: 'ToPoint',
from: [-1.59, -1.54],
to: [0.46, -5.82],
units: { type: 'Mm' },
tag: null,
__geoMeta: {
id: expect.any(String),
Expand Down Expand Up @@ -229,6 +234,7 @@ const sk2 = startSketchOn('XY')
type: 'ToPoint',
from: [0, 0],
to: [-2.5, 0],
units: { type: 'Mm' },
tag: null,
__geoMeta: {
id: expect.any(String),
Expand All @@ -239,6 +245,7 @@ const sk2 = startSketchOn('XY')
type: 'ToPoint',
from: [-2.5, 0],
to: [0, 10],
units: { type: 'Mm' },
tag: {
end: expect.any(Number),
start: expect.any(Number),
Expand All @@ -254,6 +261,7 @@ const sk2 = startSketchOn('XY')
type: 'ToPoint',
from: [0, 10],
to: [2.5, 0],
units: { type: 'Mm' },
tag: null,
__geoMeta: {
id: expect.any(String),
Expand Down Expand Up @@ -335,6 +343,7 @@ const sk2 = startSketchOn('XY')
type: 'ToPoint',
from: [0, 0],
to: [-2.5, 0],
units: { type: 'Mm' },
tag: null,
__geoMeta: {
id: expect.any(String),
Expand All @@ -345,6 +354,7 @@ const sk2 = startSketchOn('XY')
type: 'ToPoint',
from: [-2.5, 0],
to: [0, 3],
units: { type: 'Mm' },
tag: {
end: expect.any(Number),
start: expect.any(Number),
Expand All @@ -360,6 +370,7 @@ const sk2 = startSketchOn('XY')
type: 'ToPoint',
from: [0, 3],
to: [2.5, 0],
units: { type: 'Mm' },
tag: null,
__geoMeta: {
id: expect.any(String),
Expand Down
7 changes: 7 additions & 0 deletions src/lang/executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const newVar = myVar + 1`
type: 'ToPoint',
to: [0, 2],
from: [0, 0],
units: { type: 'Mm' },
__geoMeta: {
sourceRange: [expect.any(Number), expect.any(Number), 0],
id: expect.any(String),
Expand All @@ -87,6 +88,7 @@ const newVar = myVar + 1`
type: 'ToPoint',
to: [2, 3],
from: [0, 2],
units: { type: 'Mm' },
tag: null,
__geoMeta: {
sourceRange: [expect.any(Number), expect.any(Number), 0],
Expand All @@ -97,6 +99,7 @@ const newVar = myVar + 1`
type: 'ToPoint',
to: [5, -1],
from: [2, 3],
units: { type: 'Mm' },
__geoMeta: {
sourceRange: [expect.any(Number), expect.any(Number), 0],
id: expect.any(String),
Expand Down Expand Up @@ -165,6 +168,7 @@ const newVar = myVar + 1`
start: {
to: [0, 0],
from: [0, 0],
units: { type: 'Mm' },
tag: null,
__geoMeta: {
id: expect.any(String),
Expand All @@ -188,6 +192,7 @@ const newVar = myVar + 1`
type: 'ToPoint',
to: [1, 1],
from: [0, 0],
units: { type: 'Mm' },
tag: null,
__geoMeta: {
sourceRange: [expect.any(Number), expect.any(Number), 0],
Expand All @@ -198,6 +203,7 @@ const newVar = myVar + 1`
type: 'ToPoint',
to: [0, 1],
from: [1, 1],
units: { type: 'Mm' },
__geoMeta: {
sourceRange: [expect.any(Number), expect.any(Number), 0],
id: expect.any(String),
Expand All @@ -213,6 +219,7 @@ const newVar = myVar + 1`
type: 'ToPoint',
to: [1, 1],
from: [0, 1],
units: { type: 'Mm' },
tag: null,
__geoMeta: {
sourceRange: [expect.any(Number), expect.any(Number), 0],
Expand Down
2 changes: 2 additions & 0 deletions src/lang/std/sketchConstraints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ part001 = startSketchOn('XY')
type: 'ToPoint',
to: [5.62, 1.79],
from: [3.48, 0.44],
units: { type: 'Mm' },
tag: null,
})
})
Expand All @@ -401,6 +402,7 @@ part001 = startSketchOn('XY')
expect(segment).toEqual({
to: [0, 0.04],
from: [0, 0.04],
units: { type: 'Mm' },
tag: null,
type: 'Base',
})
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-lib/derive-docs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ fn do_stdlib_inner(
let label_required = !(i == 0 && metadata.unlabeled_first);
if ty_string != "ExecState" && ty_string != "Args" {
let schema = quote! {
generator.root_schema_for::<#ty_ident>()
#docs_crate::cleanup_number_tuples_root(generator.root_schema_for::<#ty_ident>())
};
arg_types.push(quote! {
#docs_crate::StdLibFnArg {
Expand Down Expand Up @@ -393,7 +393,7 @@ 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 = generator.root_schema_for::<#return_type_inner>();
let schema = #docs_crate::cleanup_number_tuples_root(generator.root_schema_for::<#return_type_inner>());
Some(#docs_crate::StdLibFnArg {
name: "".to_string(),
type_: #ret_ty_string.to_string(),
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-lib/derive-docs/tests/args_with_lifetime.gen
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl crate::docs::StdLibFn for SomeFn {
vec![crate::docs::StdLibFnArg {
name: "data".to_string(),
type_: "Foo".to_string(),
schema: generator.root_schema_for::<Foo>(),
schema: crate::docs::cleanup_number_tuples_root(generator.root_schema_for::<Foo>()),
required: true,
label_required: true,
description: String::new().to_string(),
Expand All @@ -123,7 +123,7 @@ 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 = generator.root_schema_for::<i32>();
let schema = crate::docs::cleanup_number_tuples_root(generator.root_schema_for::<i32>());
Some(crate::docs::StdLibFnArg {
name: "".to_string(),
type_: "i32".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-lib/derive-docs/tests/args_with_refs.gen
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl crate::docs::StdLibFn for SomeFn {
vec![crate::docs::StdLibFnArg {
name: "data".to_string(),
type_: "string".to_string(),
schema: generator.root_schema_for::<str>(),
schema: crate::docs::cleanup_number_tuples_root(generator.root_schema_for::<str>()),
required: true,
label_required: true,
description: String::new().to_string(),
Expand All @@ -123,7 +123,7 @@ 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 = generator.root_schema_for::<i32>();
let schema = crate::docs::cleanup_number_tuples_root(generator.root_schema_for::<i32>());
Some(crate::docs::StdLibFnArg {
name: "".to_string(),
type_: "i32".to_string(),
Expand Down
6 changes: 4 additions & 2 deletions src/wasm-lib/derive-docs/tests/array.gen
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ impl crate::docs::StdLibFn for Show {
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "[number]".to_string(),
schema: generator.root_schema_for::<[f64; 2usize]>(),
schema: crate::docs::cleanup_number_tuples_root(
generator.root_schema_for::<[f64; 2usize]>(),
),
required: true,
label_required: true,
description: String::new().to_string(),
Expand All @@ -184,7 +186,7 @@ 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 = generator.root_schema_for::<f64>();
let schema = crate::docs::cleanup_number_tuples_root(generator.root_schema_for::<f64>());
Some(crate::docs::StdLibFnArg {
name: "".to_string(),
type_: "number".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-lib/derive-docs/tests/box.gen
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl crate::docs::StdLibFn for Show {
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "number".to_string(),
schema: generator.root_schema_for::<f64>(),
schema: crate::docs::cleanup_number_tuples_root(generator.root_schema_for::<f64>()),
required: true,
label_required: true,
description: String::new().to_string(),
Expand All @@ -124,7 +124,7 @@ 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 = generator.root_schema_for::<f64>();
let schema = crate::docs::cleanup_number_tuples_root(generator.root_schema_for::<f64>());
Some(crate::docs::StdLibFnArg {
name: "".to_string(),
type_: "number".to_string(),
Expand Down
7 changes: 5 additions & 2 deletions src/wasm-lib/derive-docs/tests/doc_comment_with_code.gen
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ impl crate::docs::StdLibFn for MyFunc {
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "kittycad::types::InputFormat".to_string(),
schema: generator.root_schema_for::<Option<kittycad::types::InputFormat>>(),
schema: crate::docs::cleanup_number_tuples_root(
generator.root_schema_for::<Option<kittycad::types::InputFormat>>(),
),
required: false,
label_required: true,
description: String::new().to_string(),
Expand All @@ -185,7 +187,8 @@ 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 = generator.root_schema_for::<Vec<Sketch>>();
let schema =
crate::docs::cleanup_number_tuples_root(generator.root_schema_for::<Vec<Sketch>>());
Some(crate::docs::StdLibFnArg {
name: "".to_string(),
type_: "[Sketch]".to_string(),
Expand Down
10 changes: 7 additions & 3 deletions src/wasm-lib/derive-docs/tests/lineTo.gen
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ impl crate::docs::StdLibFn for LineTo {
crate::docs::StdLibFnArg {
name: "data".to_string(),
type_: "LineToData".to_string(),
schema: generator.root_schema_for::<LineToData>(),
schema: crate::docs::cleanup_number_tuples_root(
generator.root_schema_for::<LineToData>(),
),
required: true,
label_required: true,
description: String::new().to_string(),
Expand All @@ -183,7 +185,9 @@ impl crate::docs::StdLibFn for LineTo {
crate::docs::StdLibFnArg {
name: "sketch".to_string(),
type_: "Sketch".to_string(),
schema: generator.root_schema_for::<Sketch>(),
schema: crate::docs::cleanup_number_tuples_root(
generator.root_schema_for::<Sketch>(),
),
required: true,
label_required: true,
description: "the sketch you're adding the line to".to_string(),
Expand All @@ -196,7 +200,7 @@ 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 = generator.root_schema_for::<Sketch>();
let schema = crate::docs::cleanup_number_tuples_root(generator.root_schema_for::<Sketch>());
Some(crate::docs::StdLibFnArg {
name: "".to_string(),
type_: "Sketch".to_string(),
Expand Down
6 changes: 4 additions & 2 deletions src/wasm-lib/derive-docs/tests/min.gen
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ impl crate::docs::StdLibFn for Min {
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "[number]".to_string(),
schema: generator.root_schema_for::<Vec<f64>>(),
schema: crate::docs::cleanup_number_tuples_root(
generator.root_schema_for::<Vec<f64>>(),
),
required: true,
label_required: true,
description: String::new().to_string(),
Expand All @@ -184,7 +186,7 @@ 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 = generator.root_schema_for::<f64>();
let schema = crate::docs::cleanup_number_tuples_root(generator.root_schema_for::<f64>());
Some(crate::docs::StdLibFnArg {
name: "".to_string(),
type_: "number".to_string(),
Expand Down
6 changes: 4 additions & 2 deletions src/wasm-lib/derive-docs/tests/option.gen
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ impl crate::docs::StdLibFn for Show {
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "number".to_string(),
schema: generator.root_schema_for::<Option<f64>>(),
schema: crate::docs::cleanup_number_tuples_root(
generator.root_schema_for::<Option<f64>>(),
),
required: false,
label_required: true,
description: String::new().to_string(),
Expand All @@ -124,7 +126,7 @@ 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 = generator.root_schema_for::<f64>();
let schema = crate::docs::cleanup_number_tuples_root(generator.root_schema_for::<f64>());
Some(crate::docs::StdLibFnArg {
name: "".to_string(),
type_: "number".to_string(),
Expand Down
6 changes: 4 additions & 2 deletions src/wasm-lib/derive-docs/tests/option_input_format.gen
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ impl crate::docs::StdLibFn for Import {
vec![crate::docs::StdLibFnArg {
name: "args".to_string(),
type_: "kittycad::types::InputFormat".to_string(),
schema: generator.root_schema_for::<Option<kittycad::types::InputFormat>>(),
schema: crate::docs::cleanup_number_tuples_root(
generator.root_schema_for::<Option<kittycad::types::InputFormat>>(),
),
required: false,
label_required: true,
description: String::new().to_string(),
Expand All @@ -124,7 +126,7 @@ 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 = generator.root_schema_for::<f64>();
let schema = crate::docs::cleanup_number_tuples_root(generator.root_schema_for::<f64>());
Some(crate::docs::StdLibFnArg {
name: "".to_string(),
type_: "number".to_string(),
Expand Down
Loading

0 comments on commit 9ca6727

Please sign in to comment.