Skip to content

fix(resources): fill path placeholders by param name, not position - #1068

Open
littlewoo-legora wants to merge 1 commit into
launchdarkly:mainfrom
littlewoo-legora:fix/path-params-by-name
Open

littlewoo-legora wants to merge 1 commit into
launchdarkly:mainfrom
littlewoo-legora:fix/path-params-by-name

Conversation

@littlewoo-legora

@littlewoo-legora littlewoo-legora commented Dec 2, 2026 •

Copy link
Copy Markdown

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Tested on macOS (arm64) with Go 1.27.3; not on other platforms.

Related issues

Fixes #1067.

Describe the solution you've provided

buildURLWithParams filled the {…} placeholders in a path by position, in the order of the command's Params list. Twelve generated commands declare their params in a different order from their path, so --flag and --environment (or --segment and --environment) landed in each other's place. ldcli flags list-expiring-context-targets --flag my-flag --environment production requested /flags/<project>/production/expiring-targets/my-flag.

makeRequest now collects path params into a map keyed by the lower-cased camel-case param name. buildURLWithParams replaces each placeholder with the value of the same name, comparing case-insensitively so trigger-id fills {triggerID}. Every one of the 399 generated commands has a path param for each placeholder by this rule, so commands that worked before build the same URLs.

The empty-response branch, which reports the last path param as {"key": …}, keeps using the last path param in declared order.

MockClient now records the request path, and TestPathParamsFillPlaceholdersByName covers a flag-then-environment path, a segment-then-environment path and a differently capitalised id placeholder. All three cases fail on main with the values swapped.

go test ./... passes apart from internal/symbols/r8index TestGoldenIndexBytes, which fails the same way on main without this change. go mod tidy leaves go.mod and go.sum unchanged.

Describe alternatives you've considered

Emitting Params in path order from the generator. That fixes today's commands, but substitution would still depend on position, so a new endpoint could bring the bug back.

Additional context

Found while scheduling removal of an individual context target with update-expiring-targets. With the fix, the documented --flag / --environment order works against the live API.


Note

Overview
Fixes incorrect API URLs when OpenAPI path parameter order does not match the generated command’s Params list. Path segments were filled in declaration order instead of by placeholder name, so commands like flags list-expiring-context-targets could send --environment and --flag values in each other’s slots.

makeRequest now stores path flag values in a map keyed by lower-cased camel-case names; buildURLWithParams binds each {placeholder} to the matching key with case-insensitive name comparison (e.g. --id → {triggerID}). Empty DELETE-style responses still synthesize {"key": …} from the last path param in declared order, not from positional substitution.

MockClient records the request path for assertions. TestPathParamsFillPlaceholdersByName covers flag/environment, segment/environment, and mixed-case id placeholder cases that fail on main.

Reviewed by Cursor Bugbot for commit ef26219. Bugbot is set up for automated code reviews on this repo. Configure here.

Twelve generated commands declare their path params in a different order
from their path, so --flag and --environment (or --segment and
--environment) were swapped in the request URL. Substitute each
placeholder with the param of the same name, compared case-insensitively.

Fixes launchdarkly#1067.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@littlewoo-legora
littlewoo-legora requested a review from a team as a code owner December 2, 2026 10:15
@littlewoo-legora
littlewoo-legora requested review from btesfamariam and removed request for a team December 2, 2026 10:15
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.

--flag and --environment are swapped on expiring-targets and flag-triggers commands (path params filled by position)

1 participant