Skip to content

Commit 2abe6ad

Browse files
akoclaude
andcommitted
fix: REST client BASIC auth uses Rest\$ConstantValue with correct BSON key (#200)
Three root causes found and fixed: 1. Studio Pro requires Rest\$ConstantValue for BASIC auth credentials, not Rest\$StringValue. Using StringValue causes InvalidCastException when opening the document and 401 at runtime because the auth header is never sent. 2. The BSON field name for the constant reference is "Value" (matching the metamodel), not "Constant" (which was an incorrect guess). With the wrong key, Mendix can't resolve the constant → CE7073. 3. When literal strings are provided for auth credentials (e.g., Password: 'secret'), the executor now auto-creates string constants (Module.ClientName_Username / _Password) so the BSON always contains Rest\$ConstantValue references. This is transparent to the user. Also adds missing ExportLevel, Tags, Timeout, BaseUrlParameter, and OpenApiFile fields that Studio Pro always populates on REST clients. Test case: mdl-examples/bug-tests/200-basic-auth-rest-client.mdl creates a REST client pointing at httpbin.org/basic-auth with a test page for side-by-side comparison of REST client auth vs inline REST CALL auth. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8b44a5a commit 2abe6ad

File tree

6 files changed

+3914
-3853
lines changed

6 files changed

+3914
-3853
lines changed

mdl-examples/bug-tests/200-basic-auth-rest-client.mdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ CREATE CONSTANT AuthTest.ApiPass TYPE String DEFAULT 'testpass123!';
4242

4343
CREATE REST CLIENT AuthTest.HttpBinAuthAPI (
4444
BaseUrl: 'https://httpbin.org',
45-
Authentication: BASIC (Username: $ApiUser, Password: $ApiPass)
45+
Authentication: BASIC (Username: @AuthTest.ApiUser, Password: @AuthTest.ApiPass)
4646
)
4747
{
4848
/** Calls /basic-auth/testuser/testpass123! — returns 200 if auth header sent */

mdl/executor/cmd_rest_clients.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ func outputConsumedRestServiceMDL(ctx *ExecContext, svc *model.ConsumedRestServi
120120
if svc.Authentication == nil {
121121
fmt.Fprintln(w, " Authentication: NONE")
122122
} else {
123-
fmt.Fprintf(w, " Authentication: BASIC (Username: '%s', Password: '%s')\n",
124-
svc.Authentication.Username, svc.Authentication.Password)
123+
username := formatRestAuthValue(svc.Authentication.Username)
124+
password := formatRestAuthValue(svc.Authentication.Password)
125+
fmt.Fprintf(w, " Authentication: BASIC (Username: %s, Password: %s)\n",
126+
username, password)
125127
}
126128
fmt.Fprintln(w, ")")
127129
fmt.Fprintln(w, "{")
@@ -545,9 +547,10 @@ func dropRestClient(ctx *ExecContext, stmt *ast.DropRestClientStmt) error {
545547
}
546548

547549
// formatRestAuthValue formats an authentication value for MDL output.
550+
// Constant references (stored with $ prefix internally) are emitted as @Module.Constant.
548551
func formatRestAuthValue(value string) string {
549552
if strings.HasPrefix(value, "$") {
550-
return value
553+
return "@" + strings.TrimPrefix(value, "$")
551554
}
552555
return "'" + value + "'"
553556
}

mdl/grammar/MDLParser.g4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2427,7 +2427,8 @@ createRestClientStatement
24272427

24282428
restClientProperty
24292429
: identifierOrKeyword COLON STRING_LITERAL // BaseUrl: '...', Username: '...'
2430-
| identifierOrKeyword COLON VARIABLE // Username: $Constant (stored as Rest$ConstantValue)
2430+
| identifierOrKeyword COLON VARIABLE // Username: $Constant (legacy, stored as Rest$ConstantValue)
2431+
| identifierOrKeyword COLON AT qualifiedName // Username: @Module.Constant (preferred Mendix convention)
24312432
| identifierOrKeyword COLON NONE // Authentication: NONE
24322433
| identifierOrKeyword COLON BASIC LPAREN restClientProperty (COMMA restClientProperty)* RPAREN
24332434
;

mdl/grammar/parser/MDLParser.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)