Skip to content

SEND REST REQUEST writer drops parameter mappings and mis-encodes JSON body #193

@ako

Description

@ako

Problem

The SEND REST REQUEST writer (serializeRestOperationCallAction in sdk/mpr/writer_microflow_actions.go:586) emits a Microflows\$RestOperationCallAction that fails Mendix mx check whenever the called operation has parameters or a JSON body. Two distinct errors:

  • CE7054 "The parameters for '' have been updated. Please refresh the Send REST Request activity."
  • CE7067 "Request '' does not support body entity."

Reproduction

CREATE REST CLIENT MfTest.RC_TestApi
BASE URL 'https://httpbin.org'
AUTHENTICATION NONE
BEGIN
  OPERATION PostJsonTemplate
    METHOD POST
    PATH '/post'
    HEADER 'Content-Type' = 'application/json'
    PARAMETER \$Name: String
    PARAMETER \$Email: String
    BODY JSON FROM \$JsonBody
    RESPONSE JSON AS \$Result;
END;

CREATE MICROFLOW MfTest.PostJsonViaTemplate (\$Name: String, \$Email: String)
RETURNS String AS \$Result
BEGIN
  DECLARE \$JsonBody String = '{\"name\": \"' + \$Name + '\", \"email\": \"' + \$Email + '\"}';
  \$Result = SEND REST REQUEST MfTest.RC_TestApi.PostJsonTemplate
    BODY \$JsonBody;
  RETURN \$Result;
END;
/

After mxcli exec and mx check:

[error] [CE7054] "The parameters for 'PostJsonTemplate' have been updated. Please refresh the Send REST Request activity." at Send REST request activity 'PostJsonTemplate (POST)'
[error] [CE7067] "Request 'PostJsonTemplate' does not support body entity." at Send REST request activity 'PostJsonTemplate (POST)'

Root cause

serializeRestOperationCallAction writes a hard-coded skeleton:

doc = append(doc, bson.E{Key: "ParameterMappings", Value: bson.A{int32(3)}})       // empty
doc = append(doc, bson.E{Key: "QueryParameterMappings", Value: bson.A{int32(3)}})  // empty
// ...
if a.BodyVariable != nil {
    bv := bson.D{... "Microflows\$BodyVariable" ...}
    doc = append(doc, bson.E{Key: "BodyVariable", Value: bv})
}

Two problems:

  1. ParameterMappings is always empty. For an operation with N parameters, the call site must emit N Microflows\$RestOperationParameterMapping entries (or whatever the exact $Type is) binding each operation parameter to a microflow expression. Right now we ignore the operation's Parameters array entirely, so mx check complains the activity is out of date.

  2. Microflows\$BodyVariable is the wrong field for Rest\$JsonBody operations. Microflows\$BodyVariable is the entity-mapping body kind (used when the operation has Rest\$ImplicitMappingBody and you pass an entity to be export-mapped). For Rest\$JsonBody, the body string is rendered from the operation's template using variables in the calling microflow's scope — the call site must not set BodyVariable at all. Setting it triggers CE7067.

Suggested fix

In serializeRestOperationCallAction:

  1. Look up the called operation (the executor already has this — it's resolved during findRestOperation). Read its Parameters and emit one ParameterMappings entry per operation parameter, binding to the corresponding argument expression from the SEND REST REQUEST AST.
  2. Inspect the operation's Body.\$Type:
    • Rest\$JsonBody / Rest\$StringBody → do not set BodyVariable. The body expression already lives on the operation (as Value), and the calling microflow's variables resolve naturally.
    • Rest\$ImplicitMappingBody → set Microflows\$BodyVariable as today.

This will likely require threading the resolved operation (or at least its parameter list and body kind) through to the writer.

Context

Discovered while verifying #161 / #162 work and the BODY JSON FROM \$var roundtrip fix in commit 4000f8b. The body roundtrip fix is independent — this issue is purely about the call-site activity serialization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions