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
Now let's look at the Resource, Endpoint structs and existing placeholder regex usage in the codebase.
Assistant
Now let's check for existing regex for placeholders like
{var}used elsewhere in the codebase, and look at Generator.New in the generator package.Assistant
Now let's find where
g := &Generator{...}continues to see where it returns, and check for "resolveBaseURL" in templates for context.Assistant
No existing
InferEndpointTemplateVarsFromBaseURLsin tests. Let's check test files for spec_test.go related to placeholders, and search whole repo for "InferEndpointTemplateVars".Assistant
Good,
pathParamRealready matches{PLACEHOLDER}tokens. Now let's writeInferEndpointTemplateVarsFromBaseURLs. Let's find a good place to add it, perhaps nearIsEndpointTemplateVaror nearpathParamRe.Assistant
There's a pattern; I'll add a similar generic
sortedKeyshelper in spec.go (package-local), then implement the function.Assistant
Now let's add the function to spec.go. First check imports (need "sort").
Assistant
Now let's add the function after
IsEndpointTemplateVar.Assistant
Now let's build to check for compile errors.
Assistant
Downloading modules. Let's wait and re-run build.
Assistant
Build succeeds. Now let's add the call to
InferEndpointTemplateVarsFromBaseURLsin Generator.New.Assistant
Now the file is open properly. Let's retry the edit.
Assistant
Now let's build again to confirm no compile errors.
Assistant
Now let's write a reproduce script to test end-to-end: create a spec with templated BaseURL, run Generator.New and check EndpointTemplateVars and generation.
Assistant
Let's look at the shopify-type test that's referenced (buildURL with
https://{shop}test earlier around line 11255-11320) to understand test spec fixture patterns.Assistant
I'll place it inside the repo instead, in a subdir, and remove afterward.
Assistant
Inference worked and generation succeeded. Now let's verify the generated client contains buildURL support.
Assistant
Confirmed: buildURL/resolveBaseURL support is present in the generated client. Now let's build the generated client to confirm it compiles.
Assistant
Missing go.sum entries — let's try
go mod tidyto fetch and verify buildability.Assistant
The generated CLI builds successfully from an untemplated (implicit) placeholder base URL. Let's clean up the temp repro files.
Assistant
Now let's run the existing test suite for spec and generator packages to make sure nothing is broken.
Assistant
Confirmed pre-existing failure unrelated to our change (Go stdlib version vulnerability in the sandboxed environment). Let's restore our changes.
Assistant
Let's run the full generator test suite excluding the govulncheck-gated test to confirm the rest passes, and run the relevant test that already exercises EndpointTemplateVars generation.
Assistant
All tests pass except the pre-existing environment-only govulncheck failure, which is unrelated to our change (confirmed above with git stash). Let's also run the openapi and pipeline test suites since they reference EndpointTemplateVars, to be safe.
Assistant
Confirmed pre-existing failure unrelated to our change. Our changes are safe. Let's view the final diff.
Assistant
This all looks good. Now let's go through the checklist.
Assistant
Checklist review:
- If an error was reported in the issue description, I have successfully reproduced it. The issue described a missing capability (no error/crash) — before my fix, a spec with
{PLACEHOLDER}tokens inBaseURL/GraphQLEndpointPathbut no explicitEndpointTemplateVarswould generate a client with nobuildURL/template-var resolution support. I reproduced this with a throwaway repro program (specwithBaseURL: "https://{shop}"and noEndpointTemplateVars), confirming that without the new function, generation would not have inferred the placeholders (verified by reading the pre-existing code path, sinceGenerator.Newnever scanned URLs for placeholders before my change).
- If an error was reported in the issue description, I have successfully reproduced it. The issue described a missing capability (no error/crash) — before my fix, a spec with
Assistant
-
I have confirmed that my fix resolves the error. Re-ran the repro after adding
InferEndpointTemplateVarsFromBaseURLsand wiring it intoGenerator.New:EndpointTemplateVarswas correctly inferred as[shop api_version],Generate()succeeded,url.gocontainedfunc buildURL(...),client.gocalledbuildURL(c.BaseURL, path, ...), and the generated CLI's module built cleanly end-to-end (go build ./...aftergo mod tidy). -
I have thought about edge cases and made sure my fix handles them as well. Handled: nil receiver (
s == nilguard), preserving explicitEndpointTemplateVarsorder and not duplicating already-declared vars, deterministic traversal via sorted map keys forResources,Endpoints,SubResources, andTierRouting.Tiers(recursing into nested sub-resources), and scanning all documented URL-bearing fields (BaseURL,BasePath,GraphQLEndpointPath, tierBaseURLs, resource/endpoint/subresourceBaseURLoverrides). Reused the existingpathParamReregex (already used elsewhere in spec.go for path placeholders) for consistent placeholder syntax handling.
-
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 →
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 →