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
- Assistant
I’ll inspect the repository structure and locate the specification types, generator initialization, URL-bearing fields, and existing placeholder handling. Then I’ll implement inference, wire it into
Generator.New, and run focused and broader tests. - Assistant
The relevant code is in
internal/spec/spec.goandinternal/generator/generator.go. I’ll now inspect all nested URL field shapes and constructor behavior so traversal covers the exact model without assumptions. - Assistant
The model has map-backed tiers, resources, endpoints, and recursive subresources. I’ll inspect their concrete map types and existing placeholder regexes/validation semantics, then implement a nil-safe deterministic recursive scan.
- Assistant
Inference should scan only the documented URL-bearing fields (not endpoint request paths), preserve the explicit slice exactly, and append identifier-shaped placeholders in textual occurrence order. For maps, I’ll sort tier/resource/endpoint/subresource keys and recursively scan nested subresources. I’ll add the public receiver method in
spec.goand invoke it as the first action ingenerator.New, ensuring the caller sees the mutation immediately on return. - Assistant
The implementation is in place. Before testing, I’ll check for package-level helper name collisions and examine generator validation order plus generated resolver naming to ensure inference is early enough and templated base URLs produce the expected buildable output.
- Assistant
The code and templates align: any inferred variable gates
url.gogeneration andbuildURLuse. The test command could not start because this shell has neitherGOMODCACHEnorGOPATH; I’ll inspect repository conventions/environment and rerun with a local cache path, without changing project files. - Assistant
I’ll rerun focused tests with explicit
HOME,GOCACHE,GOPATH, andGOMODCACHE. I’ll also use a temporary root-level Go probe (removed immediately afterward) to verify exact ordering, de-duplication, recursion, andGenerator.Newmutation without adding repository tests. - Assistant
The probe confirms explicit order is unchanged (including explicit duplicates), inferred names are appended once, textual order is retained, and all maps recurse deterministically.
internal/specpasses.internal/generatorran broadly but one test failed only because its generated-client gate reports a new Go 1.26.4 standard-library vulnerability fixed in 1.26.5; this is environmental and unrelated to the patch.I’ll now perform the issue’s end-to-end reproduction using an existing valid fixture modified only to have an undeclared templated base URL, generate the client, confirm
url.go/resolver emission, and build the generated module. - Assistant
The repository’s
.gocacheis tracked fixture data, and using it as a live cache dirtied it extensively. I’ll restore only that cache directory and use/tmp/gocachefrom now on. Then I’ll run a temporary generation probe with a minimal valid API spec and no explicit template vars, followed bygo teston the generated module. - Assistant
Generation now reproduces the reported scenario successfully: an undeclared
{tenant}was inferred andinternal/client/url.gowas emitted. The initial generated-module test stopped before compilation because generated projects intentionally start without dependency checksums. I’ll rungo mod tidyin the temporary output, then compile/test it. I’ll also run the remaining affected repository packages using/tmp/gocache. - Assistant
The end-to-end generated client passes after normal
go mod tidy, including itsinternal/clientpackage and resolver. All related packages passed except one pipeline test about filesystem walk-error reporting; it is unrelated to URL inference and appears environment-sensitive. I’ll rerun that exact pipeline test and the focused endpoint-template generator tests, then inspect the final diff for unintended changes. - Assistant
Focused template-variable generator tests and
internal/specpass. The pipeline test fails consistently in the unchanged filesystem-walk behavior and is outside this change. Before submitting, I’ll verify the issue’s exactresolveBaseURLterminology against templates and ensure no URL-bearing field or generation gate was overlooked.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.