ISSUE DESCRIPTION Generator: emit resolveBaseURL when URL fields contain placeholders…
- User
ISSUE DESCRIPTION
Generator: emit resolveBaseURL when URL fields contain placeholders
When an API specification contains
{PLACEHOLDER}tokens in URL-bearing fields, the generator must infer those placeholder names intoEndpointTemplateVarsbefore validation and generation so the generated client includesresolveBaseURLsupport.Inspect
BaseURL,BasePath,GraphQLEndpointPath, tier base URLs, and resource, endpoint, and subresource base URLs. Preserve existing explicit entries and their order, append each newly discovered placeholder once, and use deterministic ordering when traversing maps. Generation from a templated base URL must produce a buildable client containing the URL resolver.Evaluation contract
Generator.Newmust invoke placeholder inference before it returns, so callers can observe the inferredEndpointTemplateVarsimmediately and later validation/generation uses the same populated specification. Scan every documented URL-bearing field, preserve explicit variables and their order, append each inferred name once, and make map-backed traversal deterministic.Interface
Type: Function Name: InferEndpointTemplateVarsFromBaseURLs Path: internal/spec/spec.go Input: (no parameters) Output: (no return value; mutates receiver's EndpointTemplateVars) Description: Scans the receiver's BaseURL, BasePath, GraphQLEndpointPath, tier BaseURLs, and resource/endpoint/subresource BaseURLs for
{PLACEHOLDER}tokens and appends any newly discovered placeholders to EndpointTemplateVars, preserving existing explicit entries and their order. Call after loading or modifying any URL-bearing field but before validation or code generation.ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /cli-printing-press, current file: none) bash-$
- Assistant
I'll start by exploring the repository structure and locating the relevant spec/generator code for placeholder inference.
- Assistant
Next I'll inspect the spec package and how EndpointTemplateVars and Generator.New currently work.
- Assistant
rg is not available, let me use grep.
- Assistant
Let me look at the spec.go file more carefully, especially around EndpointTemplateVars and any existing placeholder detection. Also look at Generator.New.
- Assistant
Let me look at vaccines and any existing tests or TODOs related to this feature. Also check AGENTS.md and recent changes related to InferEndpointTemplateVars.
- Assistant
Let me look at AGENTS.md and UPGRADE_LOG for context about this feature. Also search for pathParamRe and any related extraction of placeholders from URLs.
- Assistant
Let me check openapi's mergeServerTemplatePlaceholders and search for related tests or skill notes about this feature.
- Assistant
Let me look for any existing tests related to InferEndpointTemplateVars or skills/docs about this feature. Also check if there's a git branch or uncommitted work.
- Assistant
Let me search more carefully in docs and recent PRs. Also let me look at generator for resolveBaseURL specifically.
- Assistant
The issue is clear: I need to implement
InferEndpointTemplateVarsFromBaseURLson the APISpec that scans URL fields for{PLACEHOLDER}tokens and adds them to EndpointTemplateVars. Then `Generator.N... - Assistant
Let me look at the Load/Validate function and where EnrichPathParams is called. Also look at how Resources maps are iterated for determinism.
- Assistant
Also look at url.go.tmpl and whether there's resolveBaseURL already - the issue mentions resolveBaseURL specifically.
- Assistant
Next I'll check validation around template vars and Generator.New ending to find the right place for inference.
- Assistant
I'll inspect Generator.New's end and nearby EndpointTemplate helpers so I can add inference in the right place.
- Assistant
Let me see the end of Generator.New around line 540-570
- Assistant
Checking the Go version and whether tests already cover this helper.
- Assistant
Go 1.26 allows
slices.Sorted(maps.Keys(...)); I'll check existing usage patterns next. - Assistant
I'll implement the inference helper next to IsEndpointTemplateVar and wire it into Generator.New.
- Assistant
Hmm no matches? Let me try differently.
- Assistant
Implementing the method and wiring it up.
- Assistant
I'll insert InferEndpointTemplateVarsFromBaseURLs after IsEndpointTemplateVar.
- Assistant
Wiring inference into ParseBytes and Generator.New.
- Assistant
I'll add the call at the start of Generator.New and in ParseBytes.
- Assistant
Now update ParseBytes to also call inference.
- Assistant
I'll add InferEndpointTemplateVarsFromBaseURLs before validation in ParseBytes.
- Assistant
Writing a temporary test script to verify inference behavior and generator.New wiring.
- Assistant
Need to rename without _test.go suffix.
- Assistant
Need to set GOPATH/GOMODCACHE. There's a .gocache directory.
- Assistant
There's /go and ~/go. Let me set GOPATH and GOCACHE.
- Assistant
Can't use internal package from /tmp. I'll put the script inside the module.
- Assistant
All checks passed. Cleaning up the temp package and running related unit tests.
- Assistant
spec tests pass. Let me run the EndpointTemplateVar related generator tests.
- Assistant
Checking reserved-host validation with templated URLs to ensure generation still works:
- Assistant
Formatting the changed files and reviewing the final diff.
- Assistant
Restoring
.gocacheso only the intended source changes remain.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →