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 first inspect the repository structure and locate the specification and generator initialization code, then identify all relevant URL-bearing types and existing placeholder parsing behavior before making a focused change.
- Assistant
The spec already has runtime resolver generation gated by
EndpointTemplateVars, but no general inference method. I’ll now inspectGenerator.New, validation timing, and the nested resource structures to ensure every documented base URL is traversed in a stable order. - Assistant
Generator.Newcurrently mutates metadata before constructing the generator and does not infer placeholders. The generated resolver accepts identifier-style tokens ([A-Za-z_][A-Za-z0-9_]*), which is a sensible pattern to share for inference. I’ll inspect nested collection shapes and validation constraints next, including whether “subresource” is a named type or nested resource map. - Assistant
The nested model is recursive (
Resource.SubResources map[string]Resource), so the inference should recursively walk it rather than stop at one level. I’ll add an exported mutating method ininternal/spec/spec.go, using sorted map keys and preserving the existing slice exactly (including its order), then call it at the very start ofgenerator.Newso all subsequent constructor behavior and generation sees the same populated spec. Before editing, I’ll check existing regex conventions and generator test helpers to select targeted verification commands. - Assistant
I found an existing identical identifier regex for path parameters, but inference has a distinct URL-template responsibility, so I’ll give it a dedicated package-level regex near the new method. The traversal order will be: top-level scalar fields in documented order; tiers sorted by name; resources sorted by name, with each resource’s own base URL, endpoints sorted by name, then recursively sorted subresources. Duplicate occurrences and already-explicit names will be suppressed without altering the explicit slice.
- Assistant
The editor insertion replaced the closing brace of
IsEndpointTemplateVar, whichgofmtcorrectly flagged. I’ll restore that brace and also check whether the generic helper name collides with another package helper before compiling. - Assistant
The source now formats and passes diff whitespace checks, but tests did not start because this environment has both
GOMODCACHEandGOPATHunset. I’ll inspect the project’s Go version and environment, then run tests with repository-local cache paths. I’ll also use a temporary in-repository program (removed afterward) to directly verify inference ordering, idempotence, constructor observability, and generated-client buildability from an inferred templated URL. - Assistant
The spec package passed. The full generator suite compiled and ran broadly, but has unrelated environment failures: missing
$HOMEbreaks two cache tests, and an existinggovulncheckgate rejects the installed Go 1.26.4 standard library (fixed upstream in 1.26.5). I’ll now run a narrow temporary checker for the new behavior and a targeted existing generation test withHOMEconfigured, avoiding the unrelated vulnerability-gated test. - Assistant
Direct verification confirms deterministic ordering across all nested maps, preservation of explicit order, idempotence, and immediate mutation through
Generator.New. The existing resolver generation/build test also passes. To specifically reproduce the reported defect (templated base URL with no explicit variables), I’ll load a known-valid fixture, clear explicit variables, set a templated base URL, generate it, asserturl.goexists, and build the resulting client. Then I’ll review the final diff and repository status. - Assistant
The loader is
spec.Parse, so I’ll use the golden fixture and isolate all generated output under/tmp. This reproducer will verify that inference alone triggers resolver emission and that the complete generated module builds. - Assistant
The attempted fixture parse was unsuitable because that golden file is not directly an
APISpecroot. Also, pointingGOCACHEat the repository’s tracked cache caused Go’s cache cleanup to mark cache fixtures as deleted; these are unrelated and must be restored. I’ll restore only.gocache, switch all further commands to/tmp/gocache, and use a directly constructed valid minimal spec instead. - Assistant
Restoring tracked cache files leaves newly created untracked cache entries, so I’ll clean only untracked files under
.gocache(tracked files remain intact). Then the minimal spec will mirror the already-passing generator test shape, exceptEndpointTemplateVarsis intentionally omitted to exercise inference. - Assistant
The reported failure is now reproduced and resolved: a spec with
https://{tenant}.example.comand no explicit variables immediately gainstenant, emitsinternal/client/url.go, and the complete generated module builds. The generator created an untracked.localtest artifact, which I’ll remove, then run final focused tests and inspect only the intended two-file diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.