Skip to content

feat(v3): auto-fill channel parameters from message location (#139) - #328

Merged
lerenn merged 1 commit into
mainfrom
feat/139-param-location
Jun 12, 2026
Merged

lerenn merged 1 commit into
mainfrom
feat/139-param-location

Conversation

@lerenn

@lerenn lerenn commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Issue

Fixes #139 — a channel parameter's location runtime expression was parsed but never used; the parameter always had to be passed manually when sending.

Change

When a channel parameter declares a location ($message.payload#/... or $message.header#/...), the generated Send/Request functions now derive it from the outgoing message when the caller leaves it empty, while keeping it overridable:

// Fill UserId from the message ($message.payload#/userId) if not set
if params.UserId == "" {
    if v := msg.Payload.UserId; v != nil {
        params.UserId = *v
    }
}
addr := fmt.Sprintf("v3.issue139.user.%s", params.UserId)

This reuses the existing location-tree machinery (createTreeUntilLocation, referenceToStructAttributePath) already used for correlation IDs and reply addresses. Operation.setParametersLocationDependencies resolves the targeted field on the operation message and records whether it is required (pointer vs. value). A Follow() method was added to Parameter. The feature is send-side only (on receive the message does not exist yet).

Because no existing spec used parameter location, go generate ./... produces no golden-file diff outside the new test.

Test

test/v3/issues/139 sends through a capturing mock broker (no real broker needed) and asserts the published address is v3.issue139.user.abc when userId is left empty (filled from the payload), and ...override when set explicitly. The first assertion fails before the change (empty parameter ⇒ v3.issue139.user.).

🤖 Generated with Claude Code

Channel parameters that declare a `location` runtime expression were
parsed but ignored. The generated send functions now derive such a
parameter from the outgoing message (payload or header) when the caller
leaves it empty, while keeping it overridable. Reuses the same
location-tree machinery as correlation IDs / reply addresses, and adds a
Follow() method to Parameter.

Fixes #139

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lerenn
lerenn merged commit f10b8f4 into main Jun 12, 2026
5 checks passed
@lerenn
lerenn deleted the feat/139-param-location branch June 12, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsyncAPI v3: support parameters setting dynamically with location

1 participant