From a13d2832d47d262f0b3ac222a8eb889fb17c75ad Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 17 May 2023 21:45:57 +0200 Subject: [PATCH] feat(backend): non mapped values are passed as arg 'body' --- backend/windmill-api/src/jobs.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index 75010d91a752..faa9e9a05049 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -1223,8 +1223,6 @@ impl FromRequest for JsonOrForm>> where S: Send + Sync, - Json>>: FromRequest<(), axum::body::Body>, - Form>: FromRequest<(), axum::body::Body>, { type Rejection = Response; @@ -1237,8 +1235,17 @@ where if let Some(content_type) = content_type { if content_type.starts_with("application/json") { - let Json(payload) = req.extract().await.map_err(IntoResponse::into_response)?; - return Ok(Self(payload)); + let Json(payload): Json> = + req.extract().await.map_err(IntoResponse::into_response)?; + return match payload { + Some(serde_json::Value::Object(map)) => Ok(Self(Some(map))), + None => Ok(Self(None)), + Some(x) => { + let mut map = serde_json::Map::new(); + map.insert("body".to_string(), x); + Ok(Self(Some(map))) + } + }; } if content_type.starts_with("application/x-www-form-urlencoded") {