From bab3fb9fdcc921e1bb8a81e0f2b4e12558d2dde7 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 9 Feb 2021 18:56:34 -0800 Subject: move helper files to top-level directory --- codegen_openapi.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 codegen_openapi.sh (limited to 'codegen_openapi.sh') diff --git a/codegen_openapi.sh b/codegen_openapi.sh new file mode 100755 index 0000000..5c14a95 --- /dev/null +++ b/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 +./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>/_date: Option/g' src/models.rs +sed -i 's/_date: Vec>/_date: Vec/g' src/models.rs +perl -0777 -pi -e 's/_date\.push\(\n\s+chrono::DateTime::::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" -- cgit v1.2.3