diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2019-01-17 16:35:27 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2019-01-17 16:35:30 -0800 |
commit | bd439dc982232e087c53163d9f31d52e6bb340c1 (patch) | |
tree | 674ee06f34c5f30bbc7a74b2d5c1bf7a8f0e6de5 /rust/codegen_openapi2.sh | |
parent | 84c92a365620e1a0c3f36aa35395081bd1508c9c (diff) | |
download | fatcat-bd439dc982232e087c53163d9f31d52e6bb340c1.tar.gz fatcat-bd439dc982232e087c53163d9f31d52e6bb340c1.zip |
have rust codegen validate optional query params
Also lower-cases boolean processing.
Diffstat (limited to 'rust/codegen_openapi2.sh')
-rwxr-xr-x | rust/codegen_openapi2.sh | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/rust/codegen_openapi2.sh b/rust/codegen_openapi2.sh index f7d1df53..a3950c58 100755 --- a/rust/codegen_openapi2.sh +++ b/rust/codegen_openapi2.sh @@ -11,4 +11,16 @@ sed -i 's/extern crate uuid;/extern crate serde_json;\nextern crate uuid;/g' fat # Hack to fix "release_date" as Date, not DateTime sed -i 's/release_date: Option<chrono::DateTime<chrono::Utc>>/release_date: Option<chrono::NaiveDate>/g' fatcat-api-spec/src/models.rs +# Hack to require that optional params parse correctly (boolean, integer, datetime) +# If we reformat, this this should basically go from, eg: +# .and_then(|x| x.parse::<i64>() +# .ok()); +# To: +# .and_then(|x| Some(x.parse::<i64>())) +# .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) +# .map_err(|x| Response::with((status::InternalServerError, "unparsable query parameter (expected integer)".to_string())))?; +sed -i 's/.and_then(|x| x.parse::<i64>().ok());$/.and_then(|x| Some(x.parse::<i64>())).map_or_else(|| Ok(None), |x| x.map(|v| Some(v))).map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected integer)".to_string())))?;/g' fatcat-api-spec/src/server.rs +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-api-spec/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-api-spec/src/server.rs + cargo fmt |