Skip to content

Commit

Permalink
Use bigdecimal 0.4, update schemars, and handle the money-usd schema
Browse files Browse the repository at this point in the history
type.
  • Loading branch information
adamchalmers committed Sep 20, 2023
1 parent 01fbf74 commit 6ffda78
Show file tree
Hide file tree
Showing 10 changed files with 1,177 additions and 316 deletions.
22 changes: 16 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions kittycad.rs.patch.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,6 @@
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/hidden/struct.Hidden.html#method.logout"
}
},
{
"op": "add",
"path": "/paths/~1modeling~1cmd/post/x-rust",
"value": {
"example": "/// Submit one modeling operation.\n/// \n/// Response depends on which command was submitted, so unfortunately the OpenAPI schema can't generate the right response type.\nuse std::str::FromStr;\nasync fn example_modeling_cmd() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::OkModelingCmdResponse = client\n .modeling()\n .cmd(&kittycad::types::ModelingCmdReq {\n cmd: kittycad::types::ModelingCmd::CameraDragEnd {\n interaction: kittycad::types::CameraDragInteractionType::Zoom,\n window: kittycad::types::Point2D {\n x: 3.14 as f64,\n y: 3.14 as f64,\n },\n },\n cmd_id: uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/modeling/struct.Modeling.html#method.cmd"
}
},
{
"op": "add",
"path": "/paths/~1modeling~1cmd-batch/post/x-rust",
"value": {
"example": "/// Submit many modeling operations.\nuse std::str::FromStr;\nasync fn example_modeling_cmd_batch() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::ModelingOutcomes = client\n .modeling()\n .cmd_batch(&kittycad::types::ModelingCmdReqBatch {\n cmds: std::collections::HashMap::from([(\n \"some-key\".to_string(),\n kittycad::types::ModelingCmdReq {\n cmd: kittycad::types::ModelingCmd::CameraDragEnd {\n interaction: kittycad::types::CameraDragInteractionType::Zoom,\n window: kittycad::types::Point2D {\n x: 3.14 as f64,\n y: 3.14 as f64,\n },\n },\n cmd_id: uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n },\n )]),\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n",
"libDocsLink": "https://docs.rs/kittycad/latest/kittycad/modeling/struct.Modeling.html#method.cmd_batch"
}
},
{
"op": "add",
"path": "/paths/~1oauth2~1device~1auth/post/x-rust",
Expand Down
3 changes: 2 additions & 1 deletion kittycad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ license = "MIT"
anyhow = "1"
async-trait = { version = "^0.1.53", optional = true }
base64 = "0.21"
bigdecimal = { version = "0.4", features = ["serde"] }
bytes = { version = "1", features = ["serde"] }
clap = { version = "4.2.4", features = ["cargo", "derive", "env", "unicode"], optional = true }
chrono = { version = "0.4", default-features = false, features = ["serde", "std"] }
Expand All @@ -30,7 +31,7 @@ reqwest-conditional-middleware = { version = "0.2.1", optional = true }
reqwest-middleware = { version = "0.2.2", optional = true }
reqwest-retry = { version = "0.2.2", optional = true }
reqwest-tracing = { version = "0.4.4", features = ["opentelemetry_0_17"], optional = true }
schemars = { version = "0.8", features = ["bytes", "chrono", "url", "uuid1"] }
schemars = { version = "0.8.15", features = ["bigdecimal04", "bytes", "chrono", "url", "uuid1"] }
serde = { version = "1", features = ["derive"] }
serde_bytes = "0.11"
serde_json = "1"
Expand Down
65 changes: 0 additions & 65 deletions kittycad/src/modeling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,71 +12,6 @@ impl Modeling {
Self { client }
}

#[doc = "Submit one modeling operation.\n\nResponse depends on which command was submitted, so \
unfortunately the OpenAPI schema can't generate the right response \
type.\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_modeling_cmd() -> \
anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let \
result: kittycad::types::OkModelingCmdResponse = client\n .modeling()\n \
.cmd(&kittycad::types::ModelingCmdReq {\n cmd: \
kittycad::types::ModelingCmd::CameraDragEnd {\n interaction: \
kittycad::types::CameraDragInteractionType::Zoom,\n window: \
kittycad::types::Point2D {\n x: 3.14 as f64,\n \
y: 3.14 as f64,\n },\n },\n cmd_id: \
uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n })\n \
.await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn cmd<'a>(
&'a self,
body: &crate::types::ModelingCmdReq,
) -> Result<crate::types::OkModelingCmdResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!("{}/{}", self.client.base_url, "modeling/cmd"),
);
req = req.bearer_auth(&self.client.token);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
Err(crate::types::error::Error::UnexpectedResponse(resp))
}
}

#[doc = "Submit many modeling operations.\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_modeling_cmd_batch() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::ModelingOutcomes = client\n .modeling()\n .cmd_batch(&kittycad::types::ModelingCmdReqBatch {\n cmds: std::collections::HashMap::from([(\n \"some-key\".to_string(),\n kittycad::types::ModelingCmdReq {\n cmd: kittycad::types::ModelingCmd::CameraDragEnd {\n interaction: kittycad::types::CameraDragInteractionType::Zoom,\n window: kittycad::types::Point2D {\n x: 3.14 as f64,\n y: 3.14 as f64,\n },\n },\n cmd_id: uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n },\n )]),\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn cmd_batch<'a>(
&'a self,
body: &crate::types::ModelingCmdReqBatch,
) -> Result<crate::types::ModelingOutcomes, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!("{}/{}", self.client.base_url, "modeling/cmd-batch"),
);
req = req.bearer_auth(&self.client.token);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
Err(crate::types::error::Error::UnexpectedResponse(resp))
}
}

#[doc = "Open a websocket which accepts modeling commands.\n\nPass those commands to the \
engine via websocket, and pass responses back to the client. Basically, this is a \
websocket proxy between the frontend/client and the engine.\n\n**Parameters:**\n\n- \
Expand Down
6 changes: 3 additions & 3 deletions kittycad/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use futures::TryStreamExt;
use pretty_assertions::assert_eq;
use tokio_tungstenite::tungstenite::Message as WsMsg;

use crate::types::{ModelingCmd, ModelingCmdReq, PathSegment, Point3D};
use crate::types::{ModelingCmd, PathSegment, Point3D, WebSocketRequest};

fn test_client() -> crate::Client {
crate::Client::new_from_env()
Expand Down Expand Up @@ -211,7 +211,7 @@ async fn test_modeling_websocket() {
let path_id = Uuid::new_v4();
write
.send(WsMsg::Text(
serde_json::to_string(&ModelingCmdReq {
serde_json::to_string(&WebSocketRequest::ModelingCmdReq {
cmd: ModelingCmd::StartPath {},
cmd_id: path_id,
})
Expand Down Expand Up @@ -241,7 +241,7 @@ async fn test_modeling_websocket() {
for point in points {
write
.send(WsMsg::Text(
serde_json::to_string(&ModelingCmdReq {
serde_json::to_string(&WebSocketRequest::ModelingCmdReq {
cmd: ModelingCmd::ExtendPath {
path: path_id,
segment: PathSegment::Line { end: point },
Expand Down
Loading

0 comments on commit 6ffda78

Please sign in to comment.