Skip to content

Commit 4000f8b

Browse files
akoclaude
andcommitted
fix: roundtrip BODY JSON FROM \$var on consumed REST operations
Rest\$JsonBody.Value was always written as the empty string and never read back, so DESCRIBE REST CLIENT showed an empty BODY clause after roundtrip. Pass the body expression through serializeRestBody and read it back in parseRestBody so 'BODY JSON FROM \$JsonBody' survives a write/read cycle and Mendix mx check reports 0 errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 09eba0b commit 4000f8b

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

sdk/mpr/parser_rest.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,12 @@ func parseRestBody(bodyVal any, op *model.RestClientOperation) {
227227
op.BodyType = "JSON"
228228
case "Rest$JsonBody":
229229
op.BodyType = "JSON"
230+
op.BodyVariable = extractString(bodyMap["Value"])
230231
case "Rest$StringBody":
231232
op.BodyType = "FILE" // StringBody with template is used for file uploads
233+
if vt := extractBsonMap(bodyMap["ValueTemplate"]); vt != nil {
234+
op.BodyVariable = extractString(vt["Value"])
235+
}
232236
}
233237
}
234238

sdk/mpr/writer_rest.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func serializeRestMethod(op *model.RestClientOperation) bson.M {
177177
"$Type": "Rest$RestOperationMethodWithBody",
178178
"HttpMethod": httpMethod,
179179
}
180-
doc["Body"] = serializeRestBody(op.BodyType)
180+
doc["Body"] = serializeRestBody(op.BodyType, op.BodyVariable)
181181
return doc
182182
}
183183

@@ -189,7 +189,7 @@ func serializeRestMethod(op *model.RestClientOperation) bson.M {
189189
"$Type": "Rest$RestOperationMethodWithBody",
190190
"HttpMethod": httpMethod,
191191
}
192-
doc["Body"] = serializeRestBody("JSON")
192+
doc["Body"] = serializeRestBody("JSON", op.BodyVariable)
193193
return doc
194194
}
195195

@@ -204,25 +204,29 @@ func serializeRestMethod(op *model.RestClientOperation) bson.M {
204204
// serializeRestBody creates a polymorphic Body field.
205205
// Uses Rest$JsonBody instead of Rest$ImplicitMappingBody to avoid CE7247/CE0061
206206
// (ImplicitMappingBody requires entity mapping which isn't supported yet).
207-
func serializeRestBody(bodyType string) bson.M {
207+
//
208+
// bodyExpr is a Mendix expression (typically "$variableName") that produces
209+
// the JSON or file body at call time. It is stored verbatim in the BSON Value
210+
// field so a roundtrip preserves it.
211+
func serializeRestBody(bodyType, bodyExpr string) bson.M {
208212
switch strings.ToUpper(bodyType) {
209213
case "JSON":
210214
return bson.M{
211215
"$ID": idToBsonBinary(generateUUID()),
212216
"$Type": "Rest$JsonBody",
213-
"Value": "",
217+
"Value": bodyExpr,
214218
}
215219
case "FILE":
216220
return bson.M{
217221
"$ID": idToBsonBinary(generateUUID()),
218222
"$Type": "Rest$StringBody",
219-
"ValueTemplate": serializeValueTemplate(""),
223+
"ValueTemplate": serializeValueTemplate(bodyExpr),
220224
}
221225
default:
222226
return bson.M{
223227
"$ID": idToBsonBinary(generateUUID()),
224228
"$Type": "Rest$JsonBody",
225-
"Value": "",
229+
"Value": bodyExpr,
226230
}
227231
}
228232
}

0 commit comments

Comments
 (0)