summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-09-18 20:04:57 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-09-18 20:35:31 -0700
commitf48d59b52425bda851e539bc6947391ab7d516fa (patch)
tree1220f79903965889cbe1a0e4c2d3043994501a19
parent5b885f29a0c20e4e229297c24b8cc0c8371ef18c (diff)
downloadfatcat-f48d59b52425bda851e539bc6947391ab7d516fa.tar.gz
fatcat-f48d59b52425bda851e539bc6947391ab7d516fa.zip
more rust codegen hacks
Starting to fix problems where crate wouldn't actually build (!)
-rwxr-xr-xrust/codegen_openapi2.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/rust/codegen_openapi2.sh b/rust/codegen_openapi2.sh
index f0b48a47..af599ea1 100755
--- a/rust/codegen_openapi2.sh
+++ b/rust/codegen_openapi2.sh
@@ -1,9 +1,27 @@
#!/bin/sh
+echo "Running cargo-swagger..."
cargo swagger ../fatcat-openapi2.yml fatcat-openapi --docker-tag=v2.3.1
sudo chown `whoami`:`whoami` -R fatcat-openapi
git checkout fatcat-openapi/Cargo.toml
+echo "Patching..."
+
+# Hacks to fix crate naming
+sed -i 's/fatcat::/fatcat_openapi::/g' fatcat-openapi/examples/client.rs fatcat-openapi/examples/server.rs fatcat-openapi/examples/server_lib/server.rs
+sed -i 's/extern crate fatcat;/extern crate fatcat_openapi;/g' fatcat-openapi/examples/client.rs fatcat-openapi/examples/server.rs fatcat-openapi/examples/server_lib/server.rs
+
+# Squash many warnings ("error: unused doc comment")
+sed -i 's/\/\/\/ Create Mime objects/\/\/ Create Mime objects/g' fatcat-openapi/src/mimetypes.rs
+
+# 2019 edition crate imports
+sed -i 's/use models;/use crate::models;/g' fatcat-openapi/src/client.rs fatcat-openapi/src/server.rs fatcat-openapi/src/models.rs
+sed -i 's/use mimetypes;/use crate::mimetypes;/g' fatcat-openapi/src/client.rs fatcat-openapi/src/server.rs
+sed -i 's/use {/use crate::{/g' fatcat-openapi/src/client.rs fatcat-openapi/src/server.rs
+
+# weird broken auth example
+sed -i 's/chain.link_before(AllowAllMiddleware/\/\/chain.link_before(AllowAllMiddleware/g' fatcat-openapi/examples/server.rs
+
# Hack to handle "extra" JSON fields
sed -i 's/Object/serde_json::Value/g' fatcat-openapi/src/models.rs
sed -i 's/extern crate uuid;/extern crate serde_json;\nextern crate uuid;/g' fatcat-openapi/src/models.rs
@@ -27,4 +45,10 @@ sed -i 's/.and_then(|x| x.parse::<i64>().ok());$/.and_then(|x| Some(x.parse::<i6
sed -i 's/.and_then(|x| x.parse::<bool>().ok());$/.and_then(|x| Some(x.to_lowercase().parse::<bool>())).map_or_else(|| Ok(None), |x| x.map(|v| Some(v))).map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected boolean)".to_string())))?;/g' fatcat-openapi/src/server.rs
sed -i 's/.and_then(|x| x.parse::<chrono::DateTime<chrono::Utc>>().ok());$/.and_then(|x| Some(x.parse::<chrono::DateTime<chrono::Utc>>())).map_or_else(|| Ok(None), |x| x.map(|v| Some(v))).map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected UTC datetime in ISO\/RFC format)".to_string())))?;/g' fatcat-openapi/src/server.rs
+cd fatcat-openapi
+
+echo "Running cargo-fix (slow)..."
+cargo fix --allow-dirty
+
+echo "Running cargo-fmt..."
cargo fmt