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 first inspect the repository structure and locate the specification types, generator constructor, and existing URL/template-variable handling. This will establish where inference belongs and what tests or conventions already exist.
- Assistant
The existing generator already conditionally emits resolver support based on
EndpointTemplateVars, so the likely fix is centralized inference onAPISpecplus an early call ingenerator.New. I’ll inspect the full nested schema and constructor flow, including whetherNewvalidates or copies the spec, to ensure mutation is visible to callers as required. - Assistant
The schema confirms recursive resources and tier maps. I need exact
Resource/Endpointdefinitions andNewimplementation. I’ll also inspect current placeholder regex conventions to avoid introducing inconsistent token syntax. - Assistant
The established path-placeholder syntax is
{[A-Za-z_][A-Za-z0-9_]*}, which is appropriate to reuse for URLs. Determinism requires sorting each map’s keys (tiers, resources, endpoints, and recursive subresources), while placeholders within each string should retain textual occurrence order. I’ll inspectNew, validation timing, and existing spec tests/layout before implementing. - Assistant
Newmutates and retains the caller’s pointer, so invoking inference at its start satisfies immediate observability and ensures all later template decisions use the same data. I’ll addsortto the spec package, implement a nil-safe exported method near the shared placeholder regex, and recursively traverse sorted map keys. Explicit entries—including duplicates or unusual names—will remain untouched; a membership set will only prevent newly inferred duplicates and names already explicit. - Assistant
The implementation now covers all listed fields in a fixed hierarchy: top-level fields, sorted tiers, then sorted recursive resources with resource-before-endpoint-before-subresource ordering. Before broad tests, I’ll run focused package tests and a small temporary external check (removed immediately) to verify ordering/idempotence and that
generator.Newtriggers mutation. I’ll also inspect generated resolver naming because the issue specifically calls itresolveBaseURL, while current grep suggestedbuildURL/URL support may have evolved. - Assistant
Tests did not start because this environment has both
GOMODCACHEandGOPATHunset; this is infrastructure configuration rather than a code failure. More importantly, there is currently no symbol literally namedresolveBaseURL, so I need inspect the generated URL helper and client call sites to determine whether inference alone enables equivalent support or whether the expected resolver is missing from generation. Then I’ll rerun tests with a local writable module cache. - Assistant
The repository’s resolver is named
buildURLrather thanresolveBaseURL, but it performs the required base/path placeholder resolution and is emitted whenever inference populates the variable list; renaming it would break established tests and compatibility without adding behavior. I’ll now run focused tests withGOPATH=/goandGOMODCACHE=/go/pkg/mod, then create a temporary Go test file outside tracked tests only if needed to exercise exact hidden-contract-like ordering and generation behavior. - Assistant
Dependencies downloaded successfully, but Go also requires
GOCACHEbecauseHOMEis unset. The repository provides.gocache, so I’ll rerun with that absolute cache path and a temporary home. - Assistant
The focused run shows the affected spec package passes; unrelated suites mostly pass but two environmental/pre-existing gates fail: generated-client
govulncheckrejects this container’s Go 1.26.4 standard library (fixed in 1.26.5), and a pipeline filesystem-error assertion fails. No compile or inference-related failure appeared. I’ll run narrowly relevant generator tests that avoid the vulnerability gate, then use a temporary in-repository program (not a test and removed afterward) to validate every field, sorted traversal, duplicate preservation, idempotence, andNewobservability. - Assistant
The contract check and relevant generator tests pass. Running Go with the repository’s tracked
.gocacherewrote many cache artifacts, so I’ll restore only that cache directory and remove untracked cache files, preserving the two intended source edits. Then I’ll inspect the final diff and run static compilation/tests using a cache under/tmpto avoid repository noise. - Assistant
The final diff is clean and limited to the intended files. To satisfy the buildability part more directly, I’ll inspect how a known valid fixture is loaded and generated, then run a temporary program that clears explicit variables, injects a templated base URL, calls
New/Generate, verifiesurl.goexists, and runsgo teston the generated client package. The temporary program and output will live outside tracked source or be removed. - Assistant
A valid fixture-based path is available. I’ll generate from
testdata/loops.yamlafter replacing its base URL with a template and clearing explicit variables, assert inference and resolver emission, then compile/test the generatedinternal/clientpackage. This reproduces the reported failure mode specifically rather than only testing predeclared variables. - Assistant
Generation succeeded and emitted the resolver, but direct package testing requires the generated module’s normal
go mod tidystep to populatego.sumfirst. I’ll run tidy and then compile/test the generated client; this is expected setup for generated projects and not a source error.
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 →