Skip to content

Commit 362e5ca

Browse files
khode-mxclaude
andcommitted
fix: remove null OpenApiFile on non-spec clients; preserve UnitID on OR MODIFY
- writer_rest.go: drop the else-branch that wrote OpenApiFile=nil for manually-created REST clients; Studio Pro omits this field entirely for non-spec services, so writing an explicit null can corrupt existing projects - cmd_rest_clients.go: preserve the existing UnitID on CREATE OR MODIFY so any SEND REST REQUEST microflows that reference the service by ID remain valid after a re-import; applies to both the spec-driven and manual paths Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9935eba commit 362e5ca

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

mdl/executor/cmd_rest_clients.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,14 @@ func createRestClient(ctx *ExecContext, stmt *ast.CreateRestClientStmt) error {
316316
return mdlerrors.NewBackend("build hierarchy", err)
317317
}
318318

319+
var preservedID model.ID
319320
for _, existing := range existingServices {
320321
existModID := h.FindModuleID(existing.ContainerID)
321322
existModName := h.GetModuleName(existModID)
322323
if strings.EqualFold(existModName, moduleName) && strings.EqualFold(existing.Name, stmt.Name.Name) {
323324
if stmt.CreateOrModify {
324-
// Delete existing and recreate
325+
// Preserve the existing ID so SEND REST REQUEST references stay valid after replace.
326+
preservedID = existing.ID
325327
if err := ctx.Backend.DeleteConsumedRestService(existing.ID); err != nil {
326328
return mdlerrors.NewBackend("delete existing rest client", err)
327329
}
@@ -348,6 +350,10 @@ func createRestClient(ctx *ExecContext, stmt *ast.CreateRestClientStmt) error {
348350
Documentation: stmt.Documentation,
349351
BaseUrl: stmt.BaseUrl,
350352
}
353+
// Preserve the existing ID on OR MODIFY so SEND REST REQUEST references stay valid.
354+
if preservedID != "" {
355+
svc.ID = preservedID
356+
}
351357

352358
// Authentication — Mendix requires Rest$ConstantValue for BASIC auth credentials
353359
// (Rest$StringValue causes InvalidCastException in Studio Pro). When literal
@@ -656,7 +662,8 @@ func createRestClientFromSpec(ctx *ExecContext, stmt *ast.CreateRestClientStmt)
656662
svc.Authentication = &model.RestAuthentication{Scheme: stmt.Authentication.Scheme}
657663
}
658664

659-
// Handle OR MODIFY: delete existing if present
665+
// Handle OR MODIFY: delete existing if present, preserving UnitID so any
666+
// SEND REST REQUEST microflows that reference this service by ID remain valid.
660667
existingServices, _ := ctx.Backend.ListConsumedRestServices()
661668
h, err := getHierarchy(ctx)
662669
if err != nil {
@@ -667,6 +674,8 @@ func createRestClientFromSpec(ctx *ExecContext, stmt *ast.CreateRestClientStmt)
667674
existModName := h.GetModuleName(existModID)
668675
if strings.EqualFold(existModName, moduleName) && strings.EqualFold(existing.Name, stmt.Name.Name) {
669676
if stmt.CreateOrModify {
677+
// Reuse the existing ID so microflow references stay valid.
678+
svc.ID = existing.ID
670679
if err := ctx.Backend.DeleteConsumedRestService(existing.ID); err != nil {
671680
return mdlerrors.NewBackend("delete existing rest client", err)
672681
}

sdk/mpr/writer_rest.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,15 @@ func (w *Writer) serializeConsumedRestService(svc *model.ConsumedRestService) ([
5656
"BaseUrlParameter": nil,
5757
}
5858

59-
// OpenApiFile: present when the service was created from an OpenAPI spec.
59+
// OpenApiFile: only present when the service was created from an OpenAPI spec.
6060
// Field name and subfield are PascalCase to match Studio Pro serialization.
61+
// Do NOT write a null entry for manually-created services — Studio Pro omits this field entirely.
6162
if svc.OpenApiContent != "" {
6263
doc["OpenApiFile"] = bson.M{
6364
"$ID": idToBsonBinary(generateUUID()),
6465
"$Type": "Rest$OpenApiFile",
6566
"Content": svc.OpenApiContent,
6667
}
67-
} else {
68-
doc["OpenApiFile"] = nil
6968
}
7069

7170
// BaseUrl as Rest$ValueTemplate

0 commit comments

Comments
 (0)