diff options
author | Bryan Newbold <bnewbold@archive.org> | 2020-06-13 15:01:32 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2020-06-13 15:01:32 -0700 |
commit | d342f7a1861d8b002f48c91836e9b9fc69eeb94c (patch) | |
tree | dc90fdbe3caeabc9f57b11bb73968bd6b115885d /rust/codegen_openapi.sh | |
parent | 4575478d953fae3068959feef80517cafc826fea (diff) | |
download | fatcat-cli-d342f7a1861d8b002f48c91836e9b9fc69eeb94c.tar.gz fatcat-cli-d342f7a1861d8b002f48c91836e9b9fc69eeb94c.zip |
meta rust files from bnewbold-cli branch
Diffstat (limited to 'rust/codegen_openapi.sh')
-rwxr-xr-x | rust/codegen_openapi.sh | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/rust/codegen_openapi.sh b/rust/codegen_openapi.sh new file mode 100755 index 0000000..f86b276 --- /dev/null +++ b/rust/codegen_openapi.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -exu +set -o pipefail + +echo "Running openapi-generator..." +OUTPUT=`pwd`/fatcat-openapi +mkdir -p $OUTPUT +cat ../fatcat-openapi3.yml | grep -v "TAGLINE$" | perl -0777 -pe "s/<\!-- STARTLONGDESCRIPTION -->.*<\!-- ENDLONGDESCRIPTION -->//s" > $OUTPUT/api.yaml + +export OPENAPI_GENERATOR_VERSION=5.0.0-SNAPSHOT +./openapi-generator-cli.sh \ + generate \ + --generator-name rust-server \ + --input-spec $OUTPUT/api.yaml \ + --output $OUTPUT \ + --package-name=fatcat-openapi \ + --generate-alias-as-model + +cd fatcat-openapi + +echo "Running cargo-fmt (first time)..." +cargo fmt + +echo "Patching..." + +# Hack to fix "release_date" (and "withdrawn_date") as Date, not DateTime +sed -i 's/_date: Option<chrono::DateTime<chrono::Utc>>/_date: Option<chrono::NaiveDate>/g' src/models.rs +sed -i 's/_date: Vec<chrono::DateTime<chrono::Utc>>/_date: Vec<chrono::NaiveDate>/g' src/models.rs +perl -0777 -pi -e 's/_date\.push\(\n\s+chrono::DateTime::<chrono::Utc>::from_str/_date\.push\(chrono::NaiveDate::from_str/gs' src/models.rs + +# unnecessary duplicate copies of API spec +rm api.yaml +rm -rf api/ + +echo "Running cargo-fmt (final time)..." +cargo fmt + +cp Cargo.toml Cargo.toml.codegen +git checkout Cargo.toml +diff Cargo.toml Cargo.toml.codegen && true +echo "Check the above diff for non-metadata changes to fatcat-openapi/Cargo.toml" |