453c6bcb14
* Split the schema contracts into one module per command file `schema/commands.rs` becomes `schema/features.rs` (solid.box, solid.extrude, FeatureResult) and `schema/inspect.rs` (engine.describe), each with its own tests file holding its `schemas_and_the_key_check_agree` key lists and its `strict_keeps_todays_errors` cases, so conversions of different command files touch different files. The shared loops become helpers in `schema/tests.rs`; the assertions are unchanged. `engine.describe` gains a key-list test, and `schema_defaults_are_valid` now covers every command with a contract. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Add shared schema field types for the next conversions For the feature commands to be converted next, each deciding acceptance with the reader the handlers already use: - `FaceRef` and `FaceRefs` (`face::face_ref`, `features::face_points`) - `EdgeRef` and `EdgeRefs` (`features::edge_points`) - `SketchRef` (`features::sketch_id`) - `FeatureCommon`: `name`, `body_name`, `body_names` and `participants`, which `add_feature` reads for every feature, flattened into a contract with `deserialize_with = "feature_common"`, which keeps the key in the message and the issue's path. The shape checks of `face_ref`, `edge_points` and `sketch_id` (and `feature_sketch`) move into pure helpers (`face_ref_form`, `edge_ref_form`, `sketch_key`) that the handlers and the types share; the handlers behave as before. Tests check that each type and its schema accept what the reader accepts (apart from a face name's byte cap and an index written `1.0`), that the contract's messages match the handlers' errors, and that the handlers still look picks up one at a time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.4 KiB
Rust
43 lines
1.4 KiB
Rust
//! Contracts and result types for the commands in `cmd/inspect.rs`.
|
|
|
|
use schemars::JsonSchema;
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_json::Value;
|
|
|
|
/// Which command to describe.
|
|
#[derive(Debug, Deserialize, JsonSchema)]
|
|
#[schemars(deny_unknown_fields)]
|
|
pub struct DescribeParams {
|
|
/// The command's id, such as `solid.extrude`.
|
|
#[serde(deserialize_with = "command_id")]
|
|
pub command: String,
|
|
}
|
|
|
|
/// A command id, with the `engine.describe` handler's message for anything else.
|
|
fn command_id<'de, D: serde::Deserializer<'de>>(d: D) -> Result<String, D::Error> {
|
|
match Value::deserialize(d)? {
|
|
Value::String(s) => Ok(s),
|
|
_ => Err(serde::de::Error::custom("must be a command id")),
|
|
}
|
|
}
|
|
|
|
/// What `engine.describe` returns.
|
|
#[derive(Debug, Serialize, JsonSchema)]
|
|
pub struct DescribeResult {
|
|
pub id: String,
|
|
pub label: String,
|
|
/// The command's parameter documentation, as prose.
|
|
pub params: String,
|
|
/// The parameters' JSON Schema, or `null` when the command has no contract yet.
|
|
pub input: Option<Value>,
|
|
/// The successful result's JSON Schema, or `null` when not described yet.
|
|
pub output: Option<Value>,
|
|
/// In the warn parameter-check mode: what the call's parameters got wrong.
|
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
pub param_warnings: Vec<String>,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "inspect_tests.rs"]
|
|
mod tests;
|