diff --git a/docs/kcl/arrayReduce.md b/docs/kcl/arrayReduce.md index 6e3228b24..1773c693b 100644 --- a/docs/kcl/arrayReduce.md +++ b/docs/kcl/arrayReduce.md @@ -17,7 +17,7 @@ arrayReduce(array: [u64], start: Sketch, reduce_fn: FunctionParam) -> Sketch | Name | Type | Description | Required | |----------|------|-------------|----------| -| `array` | [`[u64]`](/docs/kcl/types/[u64]) | | Yes | +| `array` | `[u64]` | | Yes | | `start` | [`Sketch`](/docs/kcl/types/Sketch) | A sketch is a collection of paths. | Yes | | `reduce_fn` | `FunctionParam` | | Yes | diff --git a/docs/kcl/line.md b/docs/kcl/line.md index 309292689..595104d1c 100644 --- a/docs/kcl/line.md +++ b/docs/kcl/line.md @@ -17,7 +17,7 @@ line(delta: [number], sketch: Sketch, tag?: TagDeclarator) -> Sketch | Name | Type | Description | Required | |----------|------|-------------|----------| -| `delta` | [`[number]`](/docs/kcl/types/[number]) | | Yes | +| `delta` | `[number]` | | Yes | | `sketch` | [`Sketch`](/docs/kcl/types/Sketch) | A sketch is a collection of paths. | Yes | | `tag` | [`TagDeclarator`](/docs/kcl/types#tag-declaration) | | No | diff --git a/docs/kcl/lineTo.md b/docs/kcl/lineTo.md index f7b248048..0b6ed6b93 100644 --- a/docs/kcl/lineTo.md +++ b/docs/kcl/lineTo.md @@ -17,7 +17,7 @@ lineTo(to: [number], sketch: Sketch, tag?: TagDeclarator) -> Sketch | Name | Type | Description | Required | |----------|------|-------------|----------| -| `to` | [`[number]`](/docs/kcl/types/[number]) | | Yes | +| `to` | `[number]` | | Yes | | `sketch` | [`Sketch`](/docs/kcl/types/Sketch) | A sketch is a collection of paths. | Yes | | `tag` | [`TagDeclarator`](/docs/kcl/types#tag-declaration) | | No | diff --git a/docs/kcl/loft.md b/docs/kcl/loft.md index 372407ca3..501c97c7c 100644 --- a/docs/kcl/loft.md +++ b/docs/kcl/loft.md @@ -17,7 +17,7 @@ loft(sketches: [Sketch], data?: LoftData) -> Solid | Name | Type | Description | Required | |----------|------|-------------|----------| -| `sketches` | [`[Sketch]`](/docs/kcl/types/[Sketch]) | | Yes | +| `sketches` | [`[Sketch]`](/docs/kcl/types/Sketch) | | Yes | | `data` | [`LoftData`](/docs/kcl/types/LoftData) | Data for a loft. | No | ### Returns diff --git a/docs/kcl/max.md b/docs/kcl/max.md index e2d39491c..1e1b859b0 100644 --- a/docs/kcl/max.md +++ b/docs/kcl/max.md @@ -21,7 +21,7 @@ max(args: [number]) -> number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `args` | [`[number]`](/docs/kcl/types/[number]) | | Yes | +| `args` | `[number]` | | Yes | ### Returns diff --git a/docs/kcl/min.md b/docs/kcl/min.md index 2778a44dc..92add2c48 100644 --- a/docs/kcl/min.md +++ b/docs/kcl/min.md @@ -21,7 +21,7 @@ min(args: [number]) -> number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `args` | [`[number]`](/docs/kcl/types/[number]) | | Yes | +| `args` | `[number]` | | Yes | ### Returns diff --git a/docs/kcl/mirror2d.md b/docs/kcl/mirror2d.md index 5e9709f98..63900f7fd 100644 --- a/docs/kcl/mirror2d.md +++ b/docs/kcl/mirror2d.md @@ -23,7 +23,7 @@ mirror2d(data: Mirror2dData, sketch_set: SketchSet) -> [Sketch] ### Returns -[`[Sketch]`](/docs/kcl/types/[Sketch]) +[`[Sketch]`](/docs/kcl/types/Sketch) ### Examples diff --git a/docs/kcl/patternCircular2d.md b/docs/kcl/patternCircular2d.md index 2a3a5e5ba..729718ed9 100644 --- a/docs/kcl/patternCircular2d.md +++ b/docs/kcl/patternCircular2d.md @@ -22,7 +22,7 @@ patternCircular2d(data: CircularPattern2dData, sketch_set: SketchSet) -> [Sketch ### Returns -[`[Sketch]`](/docs/kcl/types/[Sketch]) +[`[Sketch]`](/docs/kcl/types/Sketch) ### Examples diff --git a/docs/kcl/patternCircular3d.md b/docs/kcl/patternCircular3d.md index aa3175ae5..6300ace47 100644 --- a/docs/kcl/patternCircular3d.md +++ b/docs/kcl/patternCircular3d.md @@ -22,7 +22,7 @@ patternCircular3d(data: CircularPattern3dData, solid_set: SolidSet) -> [Solid] ### Returns -[`[Solid]`](/docs/kcl/types/[Solid]) +[`[Solid]`](/docs/kcl/types/Solid) ### Examples diff --git a/docs/kcl/patternLinear2d.md b/docs/kcl/patternLinear2d.md index 7911c4591..900ede48c 100644 --- a/docs/kcl/patternLinear2d.md +++ b/docs/kcl/patternLinear2d.md @@ -22,7 +22,7 @@ patternLinear2d(data: LinearPattern2dData, sketch_set: SketchSet) -> [Sketch] ### Returns -[`[Sketch]`](/docs/kcl/types/[Sketch]) +[`[Sketch]`](/docs/kcl/types/Sketch) ### Examples diff --git a/docs/kcl/patternLinear3d.md b/docs/kcl/patternLinear3d.md index 19010da74..99cf3533b 100644 --- a/docs/kcl/patternLinear3d.md +++ b/docs/kcl/patternLinear3d.md @@ -22,7 +22,7 @@ patternLinear3d(data: LinearPattern3dData, solid_set: SolidSet) -> [Solid] ### Returns -[`[Solid]`](/docs/kcl/types/[Solid]) +[`[Solid]`](/docs/kcl/types/Solid) ### Examples diff --git a/docs/kcl/patternTransform.md b/docs/kcl/patternTransform.md index 883ab3572..34f7164f5 100644 --- a/docs/kcl/patternTransform.md +++ b/docs/kcl/patternTransform.md @@ -25,7 +25,7 @@ patternTransform(total_instances: u32, transform_function: FunctionParam, solid_ ### Returns -[`[Solid]`](/docs/kcl/types/[Solid]) +[`[Solid]`](/docs/kcl/types/Solid) ### Examples diff --git a/docs/kcl/polar.md b/docs/kcl/polar.md index f15d5c7e1..25b651e2d 100644 --- a/docs/kcl/polar.md +++ b/docs/kcl/polar.md @@ -21,7 +21,7 @@ polar(data: PolarCoordsData) -> [number] ### Returns -[`[number]`](/docs/kcl/types/[number]) +`[number]` ### Examples diff --git a/docs/kcl/profileStart.md b/docs/kcl/profileStart.md index 6da2e340b..422f79203 100644 --- a/docs/kcl/profileStart.md +++ b/docs/kcl/profileStart.md @@ -21,7 +21,7 @@ profileStart(sketch: Sketch) -> [number] ### Returns -[`[number]`](/docs/kcl/types/[number]) +`[number]` ### Examples diff --git a/docs/kcl/startProfileAt.md b/docs/kcl/startProfileAt.md index c07630d92..908c2d60c 100644 --- a/docs/kcl/startProfileAt.md +++ b/docs/kcl/startProfileAt.md @@ -17,7 +17,7 @@ startProfileAt(to: [number], sketch_surface: SketchSurface, tag?: TagDeclarator) | Name | Type | Description | Required | |----------|------|-------------|----------| -| `to` | [`[number]`](/docs/kcl/types/[number]) | | Yes | +| `to` | `[number]` | | Yes | | `sketch_surface` | [`SketchSurface`](/docs/kcl/types/SketchSurface) | A sketch type. | Yes | | `tag` | [`TagDeclarator`](/docs/kcl/types#tag-declaration) | | No | diff --git a/docs/kcl/startSketchAt.md b/docs/kcl/startSketchAt.md index b86eac024..ae64c8fb2 100644 --- a/docs/kcl/startSketchAt.md +++ b/docs/kcl/startSketchAt.md @@ -17,7 +17,7 @@ startSketchAt(data: [number]) -> Sketch | Name | Type | Description | Required | |----------|------|-------------|----------| -| `data` | [`[number]`](/docs/kcl/types/[number]) | | Yes | +| `data` | `[number]` | | Yes | ### Returns diff --git a/docs/kcl/tangentialArcTo.md b/docs/kcl/tangentialArcTo.md index ed7748c66..1c7dea4ba 100644 --- a/docs/kcl/tangentialArcTo.md +++ b/docs/kcl/tangentialArcTo.md @@ -17,7 +17,7 @@ tangentialArcTo(to: [number], sketch: Sketch, tag?: TagDeclarator) -> Sketch | Name | Type | Description | Required | |----------|------|-------------|----------| -| `to` | [`[number]`](/docs/kcl/types/[number]) | | Yes | +| `to` | `[number]` | | Yes | | `sketch` | [`Sketch`](/docs/kcl/types/Sketch) | A sketch is a collection of paths. | Yes | | `tag` | [`TagDeclarator`](/docs/kcl/types#tag-declaration) | | No | diff --git a/docs/kcl/tangentialArcToRelative.md b/docs/kcl/tangentialArcToRelative.md index d634e6694..2c0f23af8 100644 --- a/docs/kcl/tangentialArcToRelative.md +++ b/docs/kcl/tangentialArcToRelative.md @@ -17,7 +17,7 @@ tangentialArcToRelative(delta: [number], sketch: Sketch, tag?: TagDeclarator) -> | Name | Type | Description | Required | |----------|------|-------------|----------| -| `delta` | [`[number]`](/docs/kcl/types/[number]) | | Yes | +| `delta` | `[number]` | | Yes | | `sketch` | [`Sketch`](/docs/kcl/types/Sketch) | A sketch is a collection of paths. | Yes | | `tag` | [`TagDeclarator`](/docs/kcl/types#tag-declaration) | | No | diff --git a/docs/kcl/types/AngledLineData.md b/docs/kcl/types/AngledLineData.md index a7359b895..cbe63d11f 100644 --- a/docs/kcl/types/AngledLineData.md +++ b/docs/kcl/types/AngledLineData.md @@ -13,17 +13,10 @@ Data to draw an angled line. An angle and length with explicitly named parameters -**Type:** `object` -## Properties - -| Property | Type | Description | Required | -|----------|------|-------------|----------| -| `angle` |`number` (`double`)| The angle of the line (in degrees). | No | -| `length` |`number` (`double`)| The length of the line. | No | ---- diff --git a/docs/kcl/types/AngledLineThatIntersectsData.md b/docs/kcl/types/AngledLineThatIntersectsData.md index 7c132fd38..78c97206e 100644 --- a/docs/kcl/types/AngledLineThatIntersectsData.md +++ b/docs/kcl/types/AngledLineThatIntersectsData.md @@ -16,8 +16,8 @@ Data for drawing an angled line that intersects with a given line. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `angle` |`number` (`double`)| The angle of the line. | No | -| `intersectTag` |`object`| The tag of the line to intersect with. | No | -| `offset` |`number` (`double`)| The offset from the intersecting line. | No | +| `angle` |`number`| The angle of the line. | No | +| `intersectTag` |[`TagIdentifier`](/docs/kcl/types#tag-identifier)| The tag of the line to intersect with. | No | +| `offset` |`number`| The offset from the intersecting line. | No | diff --git a/docs/kcl/types/AngledLineToData.md b/docs/kcl/types/AngledLineToData.md index d4e933831..00f57e83b 100644 --- a/docs/kcl/types/AngledLineToData.md +++ b/docs/kcl/types/AngledLineToData.md @@ -16,7 +16,7 @@ Data to draw an angled line to a point. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `angle` |`number` (`double`)| The angle of the line. | No | -| `to` |`number` (`double`)| The point to draw to. | No | +| `angle` |`number`| The angle of the line. | No | +| `to` |`number`| The point to draw to. | No | diff --git a/docs/kcl/types/ArcData.md b/docs/kcl/types/ArcData.md index 12025c4bd..94b0535f0 100644 --- a/docs/kcl/types/ArcData.md +++ b/docs/kcl/types/ArcData.md @@ -22,9 +22,9 @@ Angles and radius with an optional tag. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `angleStart` |`number` (`double`)| The start angle. | No | -| `angleEnd` |`number` (`double`)| The end angle. | No | -| `radius` |`number` (`double`)| The radius. | No | +| `angleStart` |`number`| The start angle. | No | +| `angleEnd` |`number`| The end angle. | No | +| `radius` |`number`| The radius. | No | ---- @@ -40,9 +40,9 @@ Center, to and radius with an optional tag. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `center` |`array`| The center. | No | -| `to` |`array`| The to point. | No | -| `radius` |`number` (`double`)| The radius. | No | +| `center` |`[number, number]`| The center. | No | +| `to` |`[number, number]`| The to point. | No | +| `radius` |`number`| The radius. | No | ---- diff --git a/docs/kcl/types/BezierData.md b/docs/kcl/types/BezierData.md index 6477cf4d0..cf822e10a 100644 --- a/docs/kcl/types/BezierData.md +++ b/docs/kcl/types/BezierData.md @@ -16,8 +16,8 @@ Data to draw a bezier curve. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `to` |`array`| The to point. | No | -| `control1` |`array`| The first control point. | No | -| `control2` |`array`| The second control point. | No | +| `to` |`[number, number]`| The to point. | No | +| `control1` |`[number, number]`| The first control point. | No | +| `control2` |`[number, number]`| The second control point. | No | diff --git a/docs/kcl/types/ChamferData.md b/docs/kcl/types/ChamferData.md index 87bad3604..08915d267 100644 --- a/docs/kcl/types/ChamferData.md +++ b/docs/kcl/types/ChamferData.md @@ -16,7 +16,7 @@ Data for chamfers. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `length` |`number` (`double`)| The length of the chamfer. | No | -| `tags` |`array`| The tags of the paths you want to chamfer. | No | +| `length` |`number`| The length of the chamfer. | No | +| `tags` |`[` **anyOf:** `string` **OR** [`TagIdentifier`](/docs/kcl/types#tag-identifier) `]`| The tags of the paths you want to chamfer. | No | diff --git a/docs/kcl/types/CircleData.md b/docs/kcl/types/CircleData.md index f894297b1..9996bef41 100644 --- a/docs/kcl/types/CircleData.md +++ b/docs/kcl/types/CircleData.md @@ -16,7 +16,7 @@ Data for drawing an circle | Property | Type | Description | Required | |----------|------|-------------|----------| -| `center` |`array`| The center of the circle. | No | -| `radius` |`number` (`double`)| The circle radius | No | +| `center` |`[number, number]`| The center of the circle. | No | +| `radius` |`number`| The circle radius | No | diff --git a/docs/kcl/types/CircularPattern2dData.md b/docs/kcl/types/CircularPattern2dData.md index a9e2c0494..22079ac81 100644 --- a/docs/kcl/types/CircularPattern2dData.md +++ b/docs/kcl/types/CircularPattern2dData.md @@ -16,9 +16,9 @@ Data for a circular pattern on a 2D sketch. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `repetitions` |`integer` (`uint32`)| The number of repetitions. Must be greater than 0. This excludes the original entity. For example, if `repetitions` is 1, the original entity will be copied once. | No | -| `center` |`array`| The center about which to make the pattern. This is a 2D vector. | No | -| `arcDegrees` |`number` (`double`)| The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No | +| `repetitions` |`integer`| The number of repetitions. Must be greater than 0. This excludes the original entity. For example, if `repetitions` is 1, the original entity will be copied once. | No | +| `center` |`[number, number]`| The center about which to make the pattern. This is a 2D vector. | No | +| `arcDegrees` |`number`| The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No | | `rotateDuplicates` |`boolean`| Whether or not to rotate the duplicates as they are copied. | No | diff --git a/docs/kcl/types/CircularPattern3dData.md b/docs/kcl/types/CircularPattern3dData.md index 201782040..7ab221f45 100644 --- a/docs/kcl/types/CircularPattern3dData.md +++ b/docs/kcl/types/CircularPattern3dData.md @@ -16,10 +16,10 @@ Data for a circular pattern on a 3D model. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `repetitions` |`integer` (`uint32`)| The number of repetitions. Must be greater than 0. This excludes the original entity. For example, if `repetitions` is 1, the original entity will be copied once. | No | -| `axis` |`array`| The axis around which to make the pattern. This is a 3D vector. | No | -| `center` |`array`| The center about which to make the pattern. This is a 3D vector. | No | -| `arcDegrees` |`number` (`double`)| The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No | +| `repetitions` |`integer`| The number of repetitions. Must be greater than 0. This excludes the original entity. For example, if `repetitions` is 1, the original entity will be copied once. | No | +| `axis` |`[number, number, number]`| The axis around which to make the pattern. This is a 3D vector. | No | +| `center` |`[number, number, number]`| The center about which to make the pattern. This is a 3D vector. | No | +| `arcDegrees` |`number`| The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No | | `rotateDuplicates` |`boolean`| Whether or not to rotate the duplicates as they are copied. | No | diff --git a/docs/kcl/types/FaceTag.md b/docs/kcl/types/FaceTag.md index 04628e773..1703e7bfe 100644 --- a/docs/kcl/types/FaceTag.md +++ b/docs/kcl/types/FaceTag.md @@ -46,18 +46,10 @@ The end face after you extruded. This could also be known as the top face. But w A tag for the face. -**Type:** `object` -## Properties - -| Property | Type | Description | Required | -|----------|------|-------------|----------| -| `value` |`string`| | No | -| `info` |`object`| Engine information for a tag. | No | -| `__meta` |`array`| | No | ---- diff --git a/docs/kcl/types/FilletData.md b/docs/kcl/types/FilletData.md index f3069f409..42e7d92e8 100644 --- a/docs/kcl/types/FilletData.md +++ b/docs/kcl/types/FilletData.md @@ -16,8 +16,8 @@ Data for fillets. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `radius` |`number` (`double`)| The radius of the fillet. | No | -| `tags` |`array`| The tags of the paths you want to fillet. | No | -| `tolerance` |`number` (`double`)| The tolerance for the fillet. | No | +| `radius` |`number`| The radius of the fillet. | No | +| `tags` |`[` **anyOf:** `string` **OR** [`TagIdentifier`](/docs/kcl/types#tag-identifier) `]`| The tags of the paths you want to fillet. | No | +| `tolerance` |`number`| The tolerance for the fillet. | No | diff --git a/docs/kcl/types/HelixData.md b/docs/kcl/types/HelixData.md index aedf2c4f2..fb39403fd 100644 --- a/docs/kcl/types/HelixData.md +++ b/docs/kcl/types/HelixData.md @@ -16,9 +16,9 @@ Data for helices. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `revolutions` |`number` (`double`)| Number of revolutions. | No | -| `angleStart` |`number` (`double`)| Start angle (in degrees). | No | +| `revolutions` |`number`| Number of revolutions. | No | +| `angleStart` |`number`| Start angle (in degrees). | No | | `ccw` |`boolean`| Is the helix rotation counter clockwise? The default is `false`. | No | -| `length` |`number` (`double`)| Length of the helix. If this argument is not provided, the height of the solid is used. | No | +| `length` |`number`| Length of the helix. If this argument is not provided, the height of the solid is used. | No | diff --git a/docs/kcl/types/ImportFormat.md b/docs/kcl/types/ImportFormat.md index 90f95eb2c..b401a4cf1 100644 --- a/docs/kcl/types/ImportFormat.md +++ b/docs/kcl/types/ImportFormat.md @@ -57,7 +57,7 @@ Wavefront OBJ format. |----------|------|-------------|----------| | `type` |enum: `obj`| | No | | `coords` |`object`| Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system. | No | -| `units` |`oneOf`| 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` |**oneOf:** enum: `cm` **OR** enum: `ft` **OR** enum: `in` **OR** enum: `m` **OR** enum: `mm` **OR** enum: `yd`| 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 | ---- @@ -75,7 +75,7 @@ The PLY Polygon File Format. |----------|------|-------------|----------| | `type` |enum: `ply`| | No | | `coords` |`object`| Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system. | No | -| `units` |`oneOf`| 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` |**oneOf:** enum: `cm` **OR** enum: `ft` **OR** enum: `in` **OR** enum: `m` **OR** enum: `mm` **OR** enum: `yd`| 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 | ---- @@ -125,7 +125,7 @@ ST**ereo**L**ithography format. |----------|------|-------------|----------| | `type` |enum: `stl`| | No | | `coords` |`object`| Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system. | No | -| `units` |`oneOf`| 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` |**oneOf:** enum: `cm` **OR** enum: `ft` **OR** enum: `in` **OR** enum: `m` **OR** enum: `mm` **OR** enum: `yd`| 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 | ---- diff --git a/docs/kcl/types/ImportedGeometry.md b/docs/kcl/types/ImportedGeometry.md index ba87f1fae..432b2174e 100644 --- a/docs/kcl/types/ImportedGeometry.md +++ b/docs/kcl/types/ImportedGeometry.md @@ -16,8 +16,8 @@ Data for an imported geometry. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `id` |`string` (`uuid`)| The ID of the imported geometry. | No | -| `value` |`array`| The original file paths. | No | -| `__meta` |`array`| | No | +| `id` |`string`| The ID of the imported geometry. | No | +| `value` |`[` `string` `]`| The original file paths. | No | +| `__meta` |`[` `object` `]`| | No | diff --git a/docs/kcl/types/LinearPattern2dData.md b/docs/kcl/types/LinearPattern2dData.md index 9d401a1ff..63747b38f 100644 --- a/docs/kcl/types/LinearPattern2dData.md +++ b/docs/kcl/types/LinearPattern2dData.md @@ -16,8 +16,8 @@ Data for a linear pattern on a 2D sketch. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `repetitions` |`integer` (`uint32`)| The number of repetitions. Must be greater than 0. This excludes the original entity. For example, if `repetitions` is 1, the original entity will be copied once. | No | -| `distance` |`number` (`double`)| The distance between each repetition. This can also be referred to as spacing. | No | -| `axis` |`array`| The axis of the pattern. This is a 2D vector. | No | +| `repetitions` |`integer`| The number of repetitions. Must be greater than 0. This excludes the original entity. For example, if `repetitions` is 1, the original entity will be copied once. | No | +| `distance` |`number`| The distance between each repetition. This can also be referred to as spacing. | No | +| `axis` |`[number, number]`| The axis of the pattern. This is a 2D vector. | No | diff --git a/docs/kcl/types/LinearPattern3dData.md b/docs/kcl/types/LinearPattern3dData.md index e7895efd9..e2674d5e0 100644 --- a/docs/kcl/types/LinearPattern3dData.md +++ b/docs/kcl/types/LinearPattern3dData.md @@ -16,8 +16,8 @@ Data for a linear pattern on a 3D model. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `repetitions` |`integer` (`uint32`)| The number of repetitions. Must be greater than 0. This excludes the original entity. For example, if `repetitions` is 1, the original entity will be copied once. | No | -| `distance` |`number` (`double`)| The distance between each repetition. This can also be referred to as spacing. | No | -| `axis` |`array`| The axis of the pattern. | No | +| `repetitions` |`integer`| The number of repetitions. Must be greater than 0. This excludes the original entity. For example, if `repetitions` is 1, the original entity will be copied once. | No | +| `distance` |`number`| The distance between each repetition. This can also be referred to as spacing. | No | +| `axis` |`[number, number, number]`| The axis of the pattern. | No | diff --git a/docs/kcl/types/LoftData.md b/docs/kcl/types/LoftData.md index c6ff38645..5364d533f 100644 --- a/docs/kcl/types/LoftData.md +++ b/docs/kcl/types/LoftData.md @@ -16,9 +16,9 @@ Data for a loft. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `vDegree` |`integer` (`uint32`)| Degree of the interpolation. Must be greater than zero. For example, use 2 for quadratic, or 3 for cubic interpolation in the V direction. This defaults to 2, if not specified. | No | +| `vDegree` |`integer`| Degree of the interpolation. Must be greater than zero. For example, use 2 for quadratic, or 3 for cubic interpolation in the V direction. This defaults to 2, if not specified. | No | | `bezApproximateRational` |`boolean`| Attempt to approximate rational curves (such as arcs) using a bezier. This will remove banding around interpolations between arcs and non-arcs. It may produce errors in other scenarios Over time, this field won't be necessary. | No | -| `baseCurveIndex` |`integer` (`uint32`)| This can be set to override the automatically determined topological base curve, which is usually the first section encountered. | No | -| `tolerance` |`number` (`double`)| Tolerance for the loft operation. | No | +| `baseCurveIndex` |`integer`| This can be set to override the automatically determined topological base curve, which is usually the first section encountered. | No | +| `tolerance` |`number`| Tolerance for the loft operation. | No | diff --git a/docs/kcl/types/Mirror2dData.md b/docs/kcl/types/Mirror2dData.md index 3e3ce3d73..d933b67a6 100644 --- a/docs/kcl/types/Mirror2dData.md +++ b/docs/kcl/types/Mirror2dData.md @@ -16,6 +16,6 @@ Data for a mirror. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `axis` |`anyOf`| Axis to use as mirror. | No | +| `axis` |**anyOf:** **oneOf:** enum: `X` **OR** enum: `Y` **OR** enum: `-X` **OR** enum: `-Y` **OR** `object` **OR** **anyOf:** `string` **OR** [`TagIdentifier`](/docs/kcl/types#tag-identifier)| Axis to use as mirror. | No | diff --git a/docs/kcl/types/PolarCoordsData.md b/docs/kcl/types/PolarCoordsData.md index 3a77d4f53..c62d965fc 100644 --- a/docs/kcl/types/PolarCoordsData.md +++ b/docs/kcl/types/PolarCoordsData.md @@ -16,7 +16,7 @@ Data for polar coordinates. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `angle` |`number` (`double`)| The angle of the line (in degrees). | No | -| `length` |`number` (`double`)| The length of the line. | No | +| `angle` |`number`| The angle of the line (in degrees). | No | +| `length` |`number`| The length of the line. | No | diff --git a/docs/kcl/types/RevolveData.md b/docs/kcl/types/RevolveData.md index a2ab43759..83c5a91b2 100644 --- a/docs/kcl/types/RevolveData.md +++ b/docs/kcl/types/RevolveData.md @@ -16,8 +16,8 @@ Data for revolution surfaces. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `angle` |`number` (`double`)| Angle to revolve (in degrees). Default is 360. | No | -| `axis` |`anyOf`| Axis of revolution. | No | -| `tolerance` |`number` (`double`)| Tolerance for the revolve operation. | No | +| `angle` |`number`| Angle to revolve (in degrees). Default is 360. | No | +| `axis` |**anyOf:** **oneOf:** enum: `X` **OR** enum: `Y` **OR** enum: `-X` **OR** enum: `-Y` **OR** `object` **OR** **anyOf:** `string` **OR** [`TagIdentifier`](/docs/kcl/types#tag-identifier)| Axis of revolution. | No | +| `tolerance` |`number`| Tolerance for the revolve operation. | No | diff --git a/docs/kcl/types/ShellData.md b/docs/kcl/types/ShellData.md index bc6f338f0..25e97b4a5 100644 --- a/docs/kcl/types/ShellData.md +++ b/docs/kcl/types/ShellData.md @@ -16,7 +16,7 @@ Data for shells. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `thickness` |`number` (`double`)| The thickness of the shell. | No | -| `faces` |`array`| The faces you want removed. | No | +| `thickness` |`number`| The thickness of the shell. | No | +| `faces` |`[` **anyOf:** **oneOf:** enum: `start` **OR** enum: `end` **OR** [`TagIdentifier`](/docs/kcl/types#tag-identifier) `]`| The faces you want removed. | No | diff --git a/docs/kcl/types/Sketch.md b/docs/kcl/types/Sketch.md index 02d78f0ba..c89794e11 100644 --- a/docs/kcl/types/Sketch.md +++ b/docs/kcl/types/Sketch.md @@ -16,11 +16,11 @@ A sketch is a collection of paths. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `id` |`string` (`uuid`)| The id of the sketch (this will change when the engine's reference to it changes. | No | -| `value` |`array`| The paths in the sketch. | No | -| `on` |`oneOf`| What the sketch is on (can be a plane or a face). | No | +| `id` |`string`| The id of the sketch (this will change when the engine's reference to it changes. | No | +| `value` |`[` **oneOf:** `object` **OR** `object` **OR** `object` **OR** `object` **OR** `object` **OR** `object` **OR** `object` `]`| The paths in the sketch. | No | +| `on` |**oneOf:** `object` **OR** `object`| What the sketch is on (can be a plane or a face). | No | | `start` |`object`| The starting path. | No | | `tags` |`object`| Tag identifiers that have been declared in this sketch. | No | -| `__meta` |`array`| Metadata. | No | +| `__meta` |`[` `object` `]`| Metadata. | No | diff --git a/docs/kcl/types/SketchData.md b/docs/kcl/types/SketchData.md index de0e33b80..c69462a8a 100644 --- a/docs/kcl/types/SketchData.md +++ b/docs/kcl/types/SketchData.md @@ -15,90 +15,6 @@ Data for a plane. -**This schema accepts exactly one of the following:** - -The XY plane. - - -**enum:** `XY` - - - - - - ----- -The opposite side of the XY plane. - - -**enum:** `-XY` - - - - - - ----- -The XZ plane. - - -**enum:** `XZ` - - - - - - ----- -The opposite side of the XZ plane. - - -**enum:** `-XZ` - - - - - - ----- -The YZ plane. - - -**enum:** `YZ` - - - - - - ----- -The opposite side of the YZ plane. - - -**enum:** `-YZ` - - - - - - ----- -A defined plane. - - -**Type:** `object` - - - - -## Properties - -| Property | Type | Description | Required | -|----------|------|-------------|----------| -| `plane` |`object`| | No | - - ----- @@ -116,14 +32,14 @@ An solid is a collection of extrude surfaces. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `id` |`string` (`uuid`)| The id of the solid. | No | -| `value` |`array`| The extrude surfaces. | No | +| `id` |`string`| The id of the solid. | No | +| `value` |`[` **oneOf:** `object` **OR** `object` **OR** `object` **OR** `object` `]`| The extrude surfaces. | No | | `sketch` |`object`| The sketch. | No | -| `height` |`number` (`double`)| The height of the solid. | No | -| `startCapId` |`string` (`uuid`)| The id of the extrusion start cap | No | -| `endCapId` |`string` (`uuid`)| The id of the extrusion end cap | No | -| `edgeCuts` |`array`| Chamfers or fillets on this solid. | No | -| `__meta` |`array`| Metadata. | No | +| `height` |`number`| The height of the solid. | No | +| `startCapId` |`string`| The id of the extrusion start cap | No | +| `endCapId` |`string`| The id of the extrusion end cap | No | +| `edgeCuts` |`[` **oneOf:** `object` **OR** `object` `]`| Chamfers or fillets on this solid. | No | +| `__meta` |`[` `object` `]`| Metadata. | No | ---- diff --git a/docs/kcl/types/SketchOrSurface.md b/docs/kcl/types/SketchOrSurface.md index d619725d6..a7814cfbb 100644 --- a/docs/kcl/types/SketchOrSurface.md +++ b/docs/kcl/types/SketchOrSurface.md @@ -30,13 +30,13 @@ A plane. | Property | Type | Description | Required | |----------|------|-------------|----------| | `type` |enum: `plane`| | No | -| `id` |`string` (`uuid`)| The id of the plane. | No | -| `value` |`oneOf`| Type for a plane. | No | +| `id` |`string`| The id of the plane. | No | +| `value` |**oneOf:** enum: `XY`, `XZ`, `YZ` **OR** enum: `Custom`| Type for a plane. | No | | `origin` |`object`| Origin of the plane. | No | | `xAxis` |`object`| What should the plane’s X axis be? | No | | `yAxis` |`object`| What should the plane’s Y axis be? | No | | `zAxis` |`object`| The z-axis (normal). | No | -| `__meta` |`array`| | No | +| `__meta` |`[` `object` `]`| | No | ---- @@ -53,13 +53,13 @@ A face. | Property | Type | Description | Required | |----------|------|-------------|----------| | `type` |enum: `face`| | No | -| `id` |`string` (`uuid`)| The id of the face. | No | +| `id` |`string`| The id of the face. | No | | `value` |`string`| The tag of the face. | No | | `xAxis` |`object`| What should the face’s X axis be? | No | | `yAxis` |`object`| What should the face’s Y axis be? | No | | `zAxis` |`object`| The z-axis (normal). | No | | `solid` |`object`| The solid the face is on. | No | -| `__meta` |`array`| | No | +| `__meta` |`[` `object` `]`| | No | ---- @@ -80,12 +80,12 @@ A sketch is a collection of paths. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `id` |`string` (`uuid`)| The id of the sketch (this will change when the engine's reference to it changes. | No | -| `value` |`array`| The paths in the sketch. | No | -| `on` |`oneOf`| What the sketch is on (can be a plane or a face). | No | +| `id` |`string`| The id of the sketch (this will change when the engine's reference to it changes. | No | +| `value` |`[` **oneOf:** `object` **OR** `object` **OR** `object` **OR** `object` **OR** `object` **OR** `object` **OR** `object` `]`| The paths in the sketch. | No | +| `on` |**oneOf:** `object` **OR** `object`| What the sketch is on (can be a plane or a face). | No | | `start` |`object`| The starting path. | No | | `tags` |`object`| Tag identifiers that have been declared in this sketch. | No | -| `__meta` |`array`| Metadata. | No | +| `__meta` |`[` `object` `]`| Metadata. | No | ---- diff --git a/docs/kcl/types/SketchSet.md b/docs/kcl/types/SketchSet.md index 2c4b5b2e2..18353b24a 100644 --- a/docs/kcl/types/SketchSet.md +++ b/docs/kcl/types/SketchSet.md @@ -24,12 +24,12 @@ A sketch is a collection of paths. | Property | Type | Description | Required | |----------|------|-------------|----------| | `type` |enum: `sketch`| | No | -| `id` |`string` (`uuid`)| The id of the sketch (this will change when the engine's reference to it changes. | No | -| `value` |`array`| The paths in the sketch. | No | -| `on` |`oneOf`| What the sketch is on (can be a plane or a face). | No | +| `id` |`string`| The id of the sketch (this will change when the engine's reference to it changes. | No | +| `value` |`[` **oneOf:** `object` **OR** `object` **OR** `object` **OR** `object` **OR** `object` **OR** `object` **OR** `object` `]`| The paths in the sketch. | No | +| `on` |**oneOf:** `object` **OR** `object`| What the sketch is on (can be a plane or a face). | No | | `start` |`object`| The starting path. | No | | `tags` |`object`| Tag identifiers that have been declared in this sketch. | No | -| `__meta` |`array`| Metadata. | No | +| `__meta` |`[` `object` `]`| Metadata. | No | ---- diff --git a/docs/kcl/types/SketchSurface.md b/docs/kcl/types/SketchSurface.md index 61a89d027..bd8ed798a 100644 --- a/docs/kcl/types/SketchSurface.md +++ b/docs/kcl/types/SketchSurface.md @@ -24,13 +24,13 @@ A plane. | Property | Type | Description | Required | |----------|------|-------------|----------| | `type` |enum: `plane`| | No | -| `id` |`string` (`uuid`)| The id of the plane. | No | -| `value` |`oneOf`| Type for a plane. | No | +| `id` |`string`| The id of the plane. | No | +| `value` |**oneOf:** enum: `XY`, `XZ`, `YZ` **OR** enum: `Custom`| Type for a plane. | No | | `origin` |`object`| Origin of the plane. | No | | `xAxis` |`object`| What should the plane’s X axis be? | No | | `yAxis` |`object`| What should the plane’s Y axis be? | No | | `zAxis` |`object`| The z-axis (normal). | No | -| `__meta` |`array`| | No | +| `__meta` |`[` `object` `]`| | No | ---- @@ -47,13 +47,13 @@ A face. | Property | Type | Description | Required | |----------|------|-------------|----------| | `type` |enum: `face`| | No | -| `id` |`string` (`uuid`)| The id of the face. | No | +| `id` |`string`| The id of the face. | No | | `value` |`string`| The tag of the face. | No | | `xAxis` |`object`| What should the face’s X axis be? | No | | `yAxis` |`object`| What should the face’s Y axis be? | No | | `zAxis` |`object`| The z-axis (normal). | No | | `solid` |`object`| The solid the face is on. | No | -| `__meta` |`array`| | No | +| `__meta` |`[` `object` `]`| | No | ---- diff --git a/docs/kcl/types/Solid.md b/docs/kcl/types/Solid.md index ce96792d6..61b807242 100644 --- a/docs/kcl/types/Solid.md +++ b/docs/kcl/types/Solid.md @@ -16,13 +16,13 @@ An solid is a collection of extrude surfaces. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `id` |`string` (`uuid`)| The id of the solid. | No | -| `value` |`array`| The extrude surfaces. | No | +| `id` |`string`| The id of the solid. | No | +| `value` |`[` **oneOf:** `object` **OR** `object` **OR** `object` **OR** `object` `]`| The extrude surfaces. | No | | `sketch` |`object`| The sketch. | No | -| `height` |`number` (`double`)| The height of the solid. | No | -| `startCapId` |`string` (`uuid`)| The id of the extrusion start cap | No | -| `endCapId` |`string` (`uuid`)| The id of the extrusion end cap | No | -| `edgeCuts` |`array`| Chamfers or fillets on this solid. | No | -| `__meta` |`array`| Metadata. | No | +| `height` |`number`| The height of the solid. | No | +| `startCapId` |`string`| The id of the extrusion start cap | No | +| `endCapId` |`string`| The id of the extrusion end cap | No | +| `edgeCuts` |`[` **oneOf:** `object` **OR** `object` `]`| Chamfers or fillets on this solid. | No | +| `__meta` |`[` `object` `]`| Metadata. | No | diff --git a/docs/kcl/types/SolidSet.md b/docs/kcl/types/SolidSet.md index b286ea3b3..dd34aa93d 100644 --- a/docs/kcl/types/SolidSet.md +++ b/docs/kcl/types/SolidSet.md @@ -24,14 +24,14 @@ An solid is a collection of extrude surfaces. | Property | Type | Description | Required | |----------|------|-------------|----------| | `type` |enum: `solid`| | No | -| `id` |`string` (`uuid`)| The id of the solid. | No | -| `value` |`array`| The extrude surfaces. | No | +| `id` |`string`| The id of the solid. | No | +| `value` |`[` **oneOf:** `object` **OR** `object` **OR** `object` **OR** `object` `]`| The extrude surfaces. | No | | `sketch` |`object`| The sketch. | No | -| `height` |`number` (`double`)| The height of the solid. | No | -| `startCapId` |`string` (`uuid`)| The id of the extrusion start cap | No | -| `endCapId` |`string` (`uuid`)| The id of the extrusion end cap | No | -| `edgeCuts` |`array`| Chamfers or fillets on this solid. | No | -| `__meta` |`array`| Metadata. | No | +| `height` |`number`| The height of the solid. | No | +| `startCapId` |`string`| The id of the extrusion start cap | No | +| `endCapId` |`string`| The id of the extrusion end cap | No | +| `edgeCuts` |`[` **oneOf:** `object` **OR** `object` `]`| Chamfers or fillets on this solid. | No | +| `__meta` |`[` `object` `]`| Metadata. | No | ---- diff --git a/docs/kcl/types/TangentialArcData.md b/docs/kcl/types/TangentialArcData.md index 02de3d88f..45e8f3313 100644 --- a/docs/kcl/types/TangentialArcData.md +++ b/docs/kcl/types/TangentialArcData.md @@ -21,8 +21,8 @@ Data to draw a tangential arc. | Property | Type | Description | Required | |----------|------|-------------|----------| -| `radius` |`number` (`double`)| Radius of the arc. Not to be confused with Raiders of the Lost Ark. | No | -| `offset` |`number` (`double`)| Offset of the arc, in degrees. | No | +| `radius` |`number`| Radius of the arc. Not to be confused with Raiders of the Lost Ark. | No | +| `offset` |`number`| Offset of the arc, in degrees. | No | ---- diff --git a/src/wasm-lib/kcl/src/docs/gen_std_tests.rs b/src/wasm-lib/kcl/src/docs/gen_std_tests.rs index 161ba6b86..9e6a2c338 100644 --- a/src/wasm-lib/kcl/src/docs/gen_std_tests.rs +++ b/src/wasm-lib/kcl/src/docs/gen_std_tests.rs @@ -1,8 +1,9 @@ -use std::collections::HashMap; +use std::collections::{BTreeMap, HashMap}; use anyhow::Result; use base64::Engine; use convert_case::Casing; +use handlebars::Renderable; use itertools::Itertools; use serde_json::json; @@ -34,7 +35,42 @@ fn init_handlebars() -> Result> { // Register the 'basename' helper hbs.register_helper( - "basename", + "times", + Box::new( + |h: &handlebars::Helper, + hb: &handlebars::Handlebars, + ctx: &handlebars::Context, + rc: &mut handlebars::RenderContext, + out: &mut dyn handlebars::Output| + -> handlebars::HelperResult { + let n = h.param(0).and_then(|v| v.value().as_u64()).ok_or_else(|| { + handlebars::RenderErrorReason::Other( + "times helper expects an integer as first parameter".to_string(), + ) + })?; + + let template = h + .template() + .ok_or_else(|| handlebars::RenderErrorReason::Other("times helper expects a block".to_string()))?; + + for i in 0..n { + let mut local_ctx = ctx.clone(); + let mut rc = rc.clone(); + let m = local_ctx.data_mut().as_object_mut().unwrap(); + m.insert("@index".to_string(), handlebars::JsonValue::Number(i.into())); + if i == 0 { + m.insert("@first".to_string(), handlebars::JsonValue::Bool(true)); + } + template.render(hb, &local_ctx, &mut rc, out)?; + } + + Ok(()) + }, + ), + ); + + hbs.register_helper( + "lte", Box::new( |h: &handlebars::Helper, _: &handlebars::Handlebars, @@ -42,9 +78,47 @@ fn init_handlebars() -> Result> { _: &mut handlebars::RenderContext, out: &mut dyn handlebars::Output| -> handlebars::HelperResult { - let param = h.param(0).and_then(|v| v.value().as_str()).unwrap_or(""); - let basename = param.split('/').last().unwrap_or(""); - out.write(basename)?; + let a = h.param(0).and_then(|v| v.value().as_f64()).ok_or_else(|| { + handlebars::RenderErrorReason::Other("lte helper expects a number as first parameter".to_string()) + })?; + + let b = h.param(1).and_then(|v| v.value().as_f64()).ok_or_else(|| { + handlebars::RenderErrorReason::Other("lte helper expects a number as second parameter".to_string()) + })?; + + let result = a <= b; + out.write(if result { "true" } else { "false" })?; + + Ok(()) + }, + ), + ); + + hbs.register_helper( + "neq", + Box::new( + |h: &handlebars::Helper, + _: &handlebars::Handlebars, + _: &handlebars::Context, + _: &mut handlebars::RenderContext, + out: &mut dyn handlebars::Output| + -> handlebars::HelperResult { + let param1 = h + .param(0) + .ok_or_else(|| { + handlebars::RenderErrorReason::Other("neq helper expects two parameters".to_string()) + })? + .value(); + let param2 = h + .param(1) + .ok_or_else(|| { + handlebars::RenderErrorReason::Other("neq helper expects two parameters".to_string()) + })? + .value(); + + let result = param1 != param2; + out.write(if result { "true" } else { "false" })?; + Ok(()) }, ), @@ -94,6 +168,50 @@ fn init_handlebars() -> Result> { ), ); + hbs.register_helper( + "pretty_enum", + Box::new( + |h: &handlebars::Helper, + _: &handlebars::Handlebars, + _: &handlebars::Context, + _: &mut handlebars::RenderContext, + out: &mut dyn handlebars::Output| + -> handlebars::HelperResult { + if let Some(enum_value) = h.param(0) { + if let Some(array) = enum_value.value().as_array() { + let pretty_options = array + .iter() + .filter_map(|v| v.as_str()) + .map(|s| format!("`{}`", s)) + .collect::>() + .join(", "); + out.write(&pretty_options)?; + return Ok(()); + } + } + out.write("Invalid enum")?; + Ok(()) + }, + ), + ); + + hbs.register_helper( + "pretty_ref", + Box::new( + |h: &handlebars::Helper, + _: &handlebars::Handlebars, + _: &handlebars::Context, + _: &mut handlebars::RenderContext, + out: &mut dyn handlebars::Output| + -> handlebars::HelperResult { + let param = h.param(0).and_then(|v| v.value().as_str()).unwrap_or(""); + let basename = param.split('/').last().unwrap_or(""); + out.write(&format!("`{}`", basename))?; + Ok(()) + }, + ), + ); + // Register helper to remove newlines from a string. hbs.register_helper( "remove_newlines", @@ -157,11 +275,11 @@ fn generate_index(combined: &HashMap>) -> Result<()> { Ok(()) } -fn generate_function(internal_fn: Box) -> Result<()> { +fn generate_function(internal_fn: Box) -> Result> { let hbs = init_handlebars()?; if internal_fn.unpublished() { - return Ok(()); + return Ok(BTreeMap::new()); } let fn_name = internal_fn.name(); @@ -194,23 +312,17 @@ fn generate_function(internal_fn: Box) -> Result<()> { .collect(); // Generate the type markdown files for each argument. - let mut types = Vec::new(); + let mut types = BTreeMap::new(); for arg in internal_fn.args() { if !arg.is_primitive()? { - generate_type(&arg.type_, &arg.schema)?; - if !types.contains(&arg.type_.to_string()) { - types.push(arg.type_.to_string()); - } + add_to_types(&arg.type_, &arg.schema, &mut types)?; } } // Generate the type markdown for the return value. if let Some(ret) = internal_fn.return_value() { if !ret.is_primitive()? { - generate_type(&ret.type_, &ret.schema)?; - if !types.contains(&ret.type_.to_string()) { - types.push(ret.type_.to_string()); - } + add_to_types(&ret.type_, &ret.schema, &mut types)?; } } @@ -240,28 +352,102 @@ fn generate_function(internal_fn: Box) -> Result<()> { }); let mut output = hbs.render("function", &data)?; + // Fix the links to the types. + output = cleanup_type_links(&output, types.keys().cloned().collect()); + expectorate::assert_contents(format!("../../../docs/kcl/{}.md", fn_name), &output); + + Ok(types) +} + +fn cleanup_static_links(output: &str) -> String { + let mut cleaned_output = output.to_string(); + // Fix the links to the types. + let link = format!("[`{}`](/docs/kcl/types#tag-declaration)", "TagDeclarator"); + cleaned_output = cleaned_output.replace("`TagDeclarator`", &link); + let link = format!("[`{}`](/docs/kcl/types#tag-identifier)", "TagIdentifier"); + cleaned_output = cleaned_output.replace("`TagIdentifier`", &link); + + cleaned_output +} + +// Fix the links to the types. +fn cleanup_type_links(output: &str, types: Vec) -> String { + let mut cleaned_output = output.to_string(); // Fix the links to the types. for type_name in types { - let formatted_type_name = format!("`{}`", type_name); - if type_name == "TagDeclarator" { - let link = format!("[`{}`](/docs/kcl/types#tag-declaration)", "TagDeclarator"); - output = output.replace(&formatted_type_name, &link); - } else if type_name == "TagIdentifier" { - let link = format!("[`{}`](/docs/kcl/types#tag-identifier)", "TagIdentifier"); - output = output.replace(&formatted_type_name, &link); + if type_name == "TagDeclarator" || type_name == "TagIdentifier" { + continue; } else { - let link = format!("[`{}`](/docs/kcl/types/{})", type_name, type_name); - output = output.replace(&formatted_type_name, &link); + let link = format!("(/docs/kcl/types/{})", type_name); + cleaned_output = + cleaned_output.replace(&format!("`{}`", type_name), &format!("[`{}`]{}", type_name, &link)); + // Do the same for the type with brackets. + cleaned_output = + cleaned_output.replace(&format!("`[{}]`", type_name), &format!("[`[{}]`]{}", type_name, link)); } } - expectorate::assert_contents(format!("../../../docs/kcl/{}.md", fn_name), &output); + // Cleanup our weird number arrays. + // TODO: This is a hack for the handlebars template being too complex. + cleaned_output = cleaned_output.replace("`[, `number`, `number`]`", "`[number, number]`"); + cleaned_output = cleaned_output.replace("`[, `number`, `number`, `number`]`", "`[number, number, number]`"); + + cleanup_static_links(&cleaned_output) +} + +fn add_to_types( + name: &str, + schema: &schemars::schema::Schema, + types: &mut BTreeMap, +) -> Result<()> { + if name.is_empty() { + return Err(anyhow::anyhow!("Empty type name")); + } + + let schemars::schema::Schema::Object(o) = schema else { + return Err(anyhow::anyhow!( + "Failed to get object schema, should have not been a primitive" + )); + }; + + // If we have an array we want to generate the type markdown files for each item in the + // array. + if let Some(array) = &o.array { + // Recursively generate the type markdown files for each item in the array. + if let Some(items) = &array.items { + match items { + schemars::schema::SingleOrVec::Single(item) => { + if is_primitive(item)?.is_some() { + return Ok(()); + } + return add_to_types(name.trim_start_matches('[').trim_end_matches(']'), item, types); + } + schemars::schema::SingleOrVec::Vec(items) => { + for item in items { + if is_primitive(item)?.is_some() { + continue; + } + add_to_types(name.trim_start_matches('[').trim_end_matches(']'), item, types)?; + } + return Ok(()); + } + } + } else { + return Err(anyhow::anyhow!("Failed to get array items")); + } + } + + types.insert(name.to_string(), schema.clone()); Ok(()) } -fn generate_type(name: &str, schema: &schemars::schema::Schema) -> Result<()> { +fn generate_type( + name: &str, + schema: &schemars::schema::Schema, + types: &BTreeMap, +) -> Result<()> { if name.is_empty() { return Err(anyhow::anyhow!("Empty type name")); } @@ -287,14 +473,14 @@ fn generate_type(name: &str, schema: &schemars::schema::Schema) -> Result<()> { if is_primitive(item)?.is_some() { return Ok(()); } - return generate_type(name.trim_start_matches('[').trim_end_matches(']'), item); + return generate_type(name.trim_start_matches('[').trim_end_matches(']'), item, types); } schemars::schema::SingleOrVec::Vec(items) => { for item in items { if is_primitive(item)?.is_some() { continue; } - generate_type(name.trim_start_matches('[').trim_end_matches(']'), item)?; + generate_type(name.trim_start_matches('[').trim_end_matches(']'), item, types)?; } return Ok(()); } @@ -315,8 +501,12 @@ fn generate_type(name: &str, schema: &schemars::schema::Schema) -> Result<()> { return Err(anyhow::anyhow!("Type name is not pascal cased: {}", name)); } - // Make sure the types directory exists. - std::fs::create_dir_all(TYPES_DIR)?; + let new_schema = recurse_and_create_references(name, schema, types)?; + let schemars::schema::Schema::Object(o) = new_schema else { + return Err(anyhow::anyhow!( + "Failed to get object schema, should have not been a primitive" + )); + }; let hbs = init_handlebars()?; @@ -333,8 +523,10 @@ fn generate_type(name: &str, schema: &schemars::schema::Schema) -> Result<()> { let data = json!(schemars::schema::Schema::Object(object)); - let output = hbs.render("type", &data)?; - std::fs::write(format!("{}/{}.md", TYPES_DIR, name), output)?; + let mut output = hbs.render("type", &data)?; + // Fix the links to the types. + output = cleanup_type_links(&output, types.keys().cloned().collect()); + expectorate::assert_contents(format!("{}/{}.md", TYPES_DIR, name), &output); Ok(()) } @@ -370,20 +562,130 @@ fn clean_function_name(name: &str) -> String { fn_name } +/// Check if a schema is the same as another schema, but don't check the description. +fn is_same_schema(sa: &schemars::schema::Schema, sb: &schemars::schema::Schema) -> bool { + let schemars::schema::Schema::Object(a) = sa else { + return sa == sb; + }; + + let schemars::schema::Schema::Object(b) = sb else { + return sa == sb; + }; + + let mut a = a.clone(); + a.metadata = None; + let mut b = b.clone(); + b.metadata = None; + + a == b +} + +/// Recursively create references for types we already know about. +fn recurse_and_create_references( + name: &str, + schema: &schemars::schema::Schema, + types: &BTreeMap, +) -> Result { + let schemars::schema::Schema::Object(o) = schema else { + return Err(anyhow::anyhow!( + "Failed to get object schema, should have not been a primitive" + )); + }; + + // Check if this is the type we already know about. + for (n, s) in types { + if is_same_schema(schema, s) && name != n && !n.starts_with("[") { + // Return a reference to the type. + let sref = schemars::schema::Schema::new_ref(n.to_string()); + // Add the existing metadata to the reference. + let schemars::schema::Schema::Object(ro) = sref else { + return Err(anyhow::anyhow!( + "Failed to get object schema, should have not been a primitive" + )); + }; + let mut ro = ro.clone(); + ro.metadata = o.metadata.clone(); + + return Ok(schemars::schema::Schema::Object(ro)); + } + } + + let mut obj = o.clone(); + + // If we have an object iterate over the properties and recursively create references. + if let Some(object) = &mut obj.object { + for (_, value) in object.properties.iter_mut() { + let new_value = recurse_and_create_references(name, value, types)?; + *value = new_value; + } + } + + // If we have an array iterate over the items and recursively create references. + if let Some(array) = &mut obj.array { + if let Some(items) = &mut array.items { + match items { + schemars::schema::SingleOrVec::Single(item) => { + let new_item = recurse_and_create_references(name, item, types)?; + *item = Box::new(new_item); + } + schemars::schema::SingleOrVec::Vec(items) => { + for item in items { + let new_item = recurse_and_create_references(name, item, types)?; + *item = new_item; + } + } + } + } + } + + // If we have subschemas iterate over them and recursively create references. + if let Some(subschema) = &mut obj.subschemas { + // Do anyOf. + if let Some(any_of) = &mut subschema.any_of { + for item in any_of { + let new_item = recurse_and_create_references(name, item, types)?; + *item = new_item; + } + } + + // Do allOf. + if let Some(all_of) = &mut subschema.all_of { + for item in all_of { + let new_item = recurse_and_create_references(name, item, types)?; + *item = new_item; + } + } + + // Do oneOf. + if let Some(one_of) = &mut subschema.one_of { + for item in one_of { + let new_item = recurse_and_create_references(name, item, types)?; + *item = new_item; + } + } + } + + Ok(schemars::schema::Schema::Object(obj.clone())) +} + #[test] fn test_generate_stdlib_markdown_docs() { - // Clean the old files. - std::fs::remove_dir_all(TYPES_DIR).unwrap_or_default(); - let stdlib = StdLib::new(); let combined = stdlib.combined(); // Generate the index which is the table of contents. generate_index(&combined).unwrap(); + let mut types = BTreeMap::new(); for key in combined.keys().sorted() { let internal_fn = combined.get(key).unwrap(); - generate_function(internal_fn.clone()).unwrap(); + let fn_types = generate_function(internal_fn.clone()).unwrap(); + types.extend(fn_types); + } + + // Generate the type markdown files. + for (name, schema) in &types { + generate_type(name, schema, &types).unwrap(); } } diff --git a/src/wasm-lib/kcl/src/docs/templates/propertyType.hbs b/src/wasm-lib/kcl/src/docs/templates/propertyType.hbs index 08b8a8bf5..b8d3a03c5 100644 --- a/src/wasm-lib/kcl/src/docs/templates/propertyType.hbs +++ b/src/wasm-lib/kcl/src/docs/templates/propertyType.hbs @@ -1,7 +1,17 @@ {{~ #if $ref ~}} -[{{basename $ref}}](#{{lowercase (basename $ref)}}){{else if anyOf ~}} -`anyOf`{{else if oneOf ~}} -`oneOf`{{else if allOf ~}} -`allOf`{{else if enum ~}} -enum: {{pretty_enum enum}}{{else ~}} -`{{type}}`{{#if format}} (`{{format}}`){{/if}}{{~/if~}} +{{pretty_ref $ref}}{{else if anyOf ~}} +**anyOf:** {{#each anyOf}}{{> propertyType this}}{{#unless @last}} **OR** {{/unless}}{{/each}}{{else if oneOf ~}} +**oneOf:** {{#each oneOf}}{{> propertyType this}}{{#unless @last}} **OR** {{/unless}}{{/each}}{{else if allOf ~}} +**allOf:** {{#each allOf}}{{> propertyType this}}{{#unless @last}} **OR** {{/unless}}{{/each}}{{else if enum ~}} +enum: {{pretty_enum enum}}{{else if items ~}} +{{~ #if maxItems ~}} +{{~ #if (lte maxItems 3) ~}} +`[{{#times maxItems ~}} +{{~ #if @first ~}}{{else ~}}, {{/if ~}}{{> propertyType ../items}}{{/times}}]`{{else ~}} +`[` {{ > propertyType items }} `]` +{{~ /if ~}}{{else ~}}`[` {{ > propertyType items }} `]` +{{~ /if ~}}{{else ~}} +`{{type}}{{~ #if format }}{{#if neq format "double" }} ({{format}}){{/if}} +{{~ /if ~}}` +{{~/if~}} + diff --git a/src/wasm-lib/kcl/src/docs/templates/schemaType.hbs b/src/wasm-lib/kcl/src/docs/templates/schemaType.hbs index 2f515b858..b28637518 100644 --- a/src/wasm-lib/kcl/src/docs/templates/schemaType.hbs +++ b/src/wasm-lib/kcl/src/docs/templates/schemaType.hbs @@ -1,7 +1,5 @@ -{{ -#if - $ref}} -[{{basename $ref}}](#{{lowercase (basename $ref)}}) +{{#if $ref}} +{{pretty_ref $ref}} {{else if anyOf}} **anyOf** {{else if oneOf}}