Skip to content

Commit

Permalink
feat(backend): non mapped values are passed as arg 'body'
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed May 17, 2023
1 parent a387c62 commit a13d283
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions backend/windmill-api/src/jobs.rs
Expand Up @@ -1223,8 +1223,6 @@ impl<S> FromRequest<S, axum::body::Body>
for JsonOrForm<Option<serde_json::Map<String, serde_json::Value>>>
where
S: Send + Sync,
Json<Option<serde_json::Map<String, serde_json::Value>>>: FromRequest<(), axum::body::Body>,
Form<serde_json::Map<String, serde_json::Value>>: FromRequest<(), axum::body::Body>,
{
type Rejection = Response;

Expand All @@ -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<Option<serde_json::Value>> =
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") {
Expand Down

0 comments on commit a13d283

Please sign in to comment.