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 TierConfig and TierRouting struct.
Assistant
Now let's find where similar placeholder regex or extraction exists (maybe already used elsewhere, e.g. for validation of path placeholders).
Assistant
Good, there's
pathParamRealready at line 1965:\{([A-Za-z_][A-Za-z0-9_]*)\}. Let's look at its usage context and also check generator.go for Generator.New.Assistant
Now let's look at
Generator.Newto see where to call the new function.Assistant
Now let's search for "resolveBaseURL" in the repo to understand how it's used/generated.
Assistant
No hard validation blocking it currently. Now let's write the
InferEndpointTemplateVarsFromBaseURLsfunction. Let's check tier BaseURL struct field again and Resource/Endpoint types for base_url. Also check for sorted map iteration helper functions already in repo (e.g.,slices.Sortusage on map keys elsewhere).Assistant
I'll insert the new function right after
promoteEndpointParamsToBody(line ~2115), beforeexpandOperations. Let's get exact line number.Assistant
Now insert the new function at line 2121 (after the closing brace, before expandOperations comment).
Assistant
Good. Now build to verify compile.
Assistant
Build succeeds. Now let's add the call in
Generator.New.Assistant
Now build and run relevant tests.
Assistant
Now let's write a quick reproduce script to test the scenario end-to-end.
Assistant
Works as expected: new placeholders appended, no duplicates, order preserved for explicit entries, deterministic map traversal. Now let's clean up and test Generator.New end-to-end producing a buildable client with resolveBaseURL/buildURL support.
Assistant
Let's look at an existing test with EndpointTemplateVars usage for pattern, and see if there's a full generate+build test we can model.
Assistant
Good, this test uses
spec.Parse(not our function) so its assertion happens beforeNew. Since loops.yaml has no placeholders, our inference won't add anything. Let's confirm and run these tests plus other generator tests.Assistant
Good, no placeholders. Now let's run the full test suite for spec and generator packages.
Assistant
Confirmed pre-existing failure unrelated to my change (Go toolchain version vulnerability). Restore my changes.
Assistant
Now let's run full generator tests except this govulncheck-failing one, and skip that specific test.
Assistant
All key tests pass. Let's run the full generator test suite excluding the govulncheck-affected test.
Assistant
All pass. Now let's test a full end-to-end scenario: spec with templated BaseURL and no explicit
endpoint_template_vars, run through Generator.New + Generate, and verify a buildable client with buildURL (the resolver).Assistant
EndpointTemplateVars was correctly inferred before Generate ran, and url.go (the buildURL resolver) got emitted. Let's now verify it's a buildable client.
Assistant
Builds successfully with the URL resolver present. Now clean up temp files.
Assistant
Now let's run broader test suite (spec, generator, openapi, pipeline) to ensure nothing else broke.
Assistant
Confirmed pre-existing failure, unrelated to our change (likely environment-specific, e.g. filesystem permission edge case). Now let's run openapi tests specifically (they passed above implicitly since not in failing list, but let's double check).
Assistant
Now let's also run the full CLI package tests since generator.New is invoked there.
Assistant
All pass. Let's view the final diff for review.
Assistant
This diff looks clean and correctly scoped. Let's remove any leftover temp files and do a final full build/test sanity check.
Assistant
No leftover temp files. Final build check.
Assistant
Now let me go through the checklist.
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 →