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:
- Assistant
I’ll inspect the specification model, generator initialization flow, and existing URL/template handling first. Then I’ll implement inference with deterministic traversal, wire it into
Generator.Newbefore validation, run focused and broader tests, and inspect the final diff. - Assistant
The repository already has resolver generation keyed solely off
EndpointTemplateVars, so the missing behavior is likely model inference and initialization timing. I’ll now inspect all relevant struct definitions and map fields to ensure every documented URL-bearing location is covered without accidentally changing unrelated template-variable semantics. - Assistant
The relevant fields are exactly
APISpecbase fields,TierConfig.BaseURL, andBaseURLonResource/Endpointrecursively throughSubResources. Existing placeholder regex already matches the intended{NAME}syntax. I’ll add the exported mutating method using sorted map keys at every map boundary, preserve the existing slice verbatim, and call it as the first operation inGenerator.Newso inference is observable immediately. - Assistant
The implementation is in place. Its traversal order is: top-level fields, tiers sorted by name, then resources sorted by name; each resource scans its own URL, endpoints sorted by name, then subresources sorted recursively. This makes “first discovery” deterministic while retaining explicit entries and repeated explicit values. I’ll run focused package tests and a temporary behavioral check covering all field categories and
Generator.New. - Assistant
The focused tests could not start because this environment has neither
GOMODCACHEnorGOPATHconfigured, and dependencies are not available in the default locations. I’ll inspect the module configuration and available caches, then use the repository’s supported setup if possible; independently I’ll still run formatting/static checks that do not require dependency downloads. - Assistant
The toolchain is present, but the first retry also revealed no
GOCACHE; dependency downloads began successfully. I’ll provide all three temporary Go cache locations and rerun the focused tests, then use the same setup for the behavioral check if downloads complete. - Assistant
Dependencies are now available and the focused packages compile.
spec,graphql, andopenapipass;generatorreaches an existingTestGenerateWithNoAuthfailure because the environment’s Go 1.26.4 standard library is flagged bygovulncheck(fixed in 1.26.5), unrelated to this change. I’ll run the direct inference check and then review status/diff for accidental files. - Assistant
The behavioral check confirms immediate inference from
Generator.Newand the expected stable result:[explicit z a base g tiera tierb ra rb ez sub]. The test run created an untracked generator-local artifact, which is not part of the fix; I’ll remove it, verify the final diff, and perform one last compile-only check where practical.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.