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 start by exploring the repository structure and understanding the codebase.
Assistant
Let me continue exploring the spec.go file and the structures involved.
Assistant
Now let me find the Generator.New function and how EndpointTemplateVars is currently used.
Assistant
Let me look at how placeholders are extracted elsewhere in the codebase.
Assistant
Let me look at how server URL placeholders are extracted in the openapi parser.
Assistant
Now let me look at how
resolveBaseURLis emitted and where EndpointTemplateVars is used in generation.Assistant
Let me look at the url.go.tmpl template and the generator's render logic around it.
Assistant
Now let me look at the generator.go around line 1718 where the url.go.tmpl is rendered to understand when it's emitted (it's gated by EndpointTemplateVars).
Assistant
Let me look at the existing spec tests for EndpointTemplateVars to understand the conventions.
Assistant
Let me look at the validation logic to understand placeholder handling and what fields contain URLs.
Assistant
Now I have a good understanding. Let me check the existing test file for any references to the generator's spec test to understand the conventions and where to place the function. Let me look at the full spec.go to find where to add the function. Let me also check the
namingpackage for anEnvVarPlaceholderhelper.Now I understand the structure. Let me plan:
-
Add
InferEndpointTemplateVarsFromBaseURLsmethod on*APISpecininternal/spec/spec.go. It scans:s.BaseURLs.BasePaths.GraphQLEndpointPath- tier BaseURLs (
s.TierRouting.Tiers- deterministic ordering) - resource BaseURLs (
s.Resources- deterministic ordering) - endpoint BaseURLs (within resources and subresources)
- subresource BaseURLs (recursively)
For each, extract
{PLACEHOLDER}tokens using a regex like\{([a-zA-Z_][a-zA-Z0-9_]*)\}. Append each newly discovered placeholder toEndpointTemplateVars, preserving existing explicit entries and their order, append each newly discovered placeholder once, and use deterministic ordering when traversing maps.
-
Assistant
The imports
regexpandslicesare already in spec.go. Now let me look at the docs/docspec parser to understand how BaseURL/EndpointTemplateVars are set, to make sure my inference covers all the cases the issue mentions.Assistant
The graphql and docs parsers don't seem to populate EndpointTemplateVars explicitly. So the inference is the path for them. Let me look at the graphql parser to see how it sets BaseURL and GraphQLEndpointPath.
Assistant
Now I understand the full picture. Let me look at the exact location to add the function and add a regex.
Assistant
Now I'll add the
InferEndpointTemplateVarsFromBaseURLsfunction and a regex pattern to spec.go. Let me insert it afterIsEndpointTemplateVar.Assistant
Now I'll add the function after
IsEndpointTemplateVar(after line 277).Assistant
I notice I have duplicate logic with the
scanURLclosure and thescanURLFieldhelper. Let me simplify by usingscanURLFieldconsistently.Assistant
Now let me build the spec package to make sure it compiles.
Assistant
GOPATH isn't set. Let me set it. There's a
binandsrcdirectory at the root (the ls output shows bin, src which are likely HOME/gols /go`? Let me check).Assistant
The spec package builds. Now let me add the call in
Generator.New. Let me look at the end ofNew.Assistant
Let me find where the
gis returned at the end ofNew. TheNewfunction constructsg := &Generator{...}then sets up funcs and returns. Let me find the return statement.Assistant
Now let me add the inference call in
Newbefore theg := &Generator{...}construction (so it's invoked before it returns). Let me add it right before theg := &Generator{line.Assistant
I need to navigate to the file first. Let me open the generator file at the right location.
Assistant
Now let me build the whole project and run the spec tests.
Assistant
Build succeeds. Now let me run the spec tests and generator tests.
Assistant
The failure is due to a pre-existing Go stdlib vulnerability flagged by
govulncheck(crypto/tls in go1.26.4), unrelated to my change. Let me confirm this is pre-existing by stashing my changes and running the same test.Assistant
Confirmed: the
TestGenerateWithNoAuthfailure is pre-existing (govulncheck stdlib vuln) and unrelated to my change. Now let me write a temporary test to verify my inference function works correctly.Assistant
My test expectation was wrong; the function produces the correct scan order (BaseURL → BasePath → GraphQLEndpointPath → tiers → resources). Let me fix the test expectation.
Assistant
All tests pass. Now let me verify the generation pipeline produces a buildable client when BaseURL has a placeholder (the core requirement). Let me look at how generation tests are structured and find a good test fixture, then write a temporary test that generates a client with a templated BaseURL and confirms
url.gois emitted.Assistant
Let me look at how existing tests generate a full client to a temp dir and run
go build, to mirror that pattern in a temporary test.Assistant
Let me look at a test that generates and runs
go buildto validate a buildable client, to mirror the pattern.Assistant
Let me look at a test that uses
go buildto validate a buildable client, e.g. tier_routing_test.go.Assistant
Let me look at the tier_routing_test for the full build pattern (go.mod setup etc).
Assistant
Now let me write a temporary generator test that verifies
NewpopulatesEndpointTemplateVarsimmediately and the generated client emitsurl.goand builds.Assistant
All temporary tests pass. The core requirement is satisfied. Now let me clean up the temporary test files and run the relevant existing tests.
Assistant
Now let me run a broader set of generator tests that don't involve govulncheck, plus the openapi/parser/profiler/pipeline tests which might be affected by the EndpointTemplateVars inference.
Assistant
A pipeline test failed. Let me see which one(s) failed.
Assistant
Let me check if this failure is pre-existing (unrelated to my change) by stashing.
Assistant
The pipeline test failure is pre-existing and unrelated. Now let me run the openapi and profiler tests to confirm they pass.
Assistant
The pipeline failure is pre-existing. Now let me check for golden tests that run full generation and compare against fixtures, which could be affected by the new url.go emission.
Assistant
Let me look at the golden tests that run full generation and compare against fixtures.
Assistant
The golden suite uses the actual
cli-printing-pressbinary. Let me check the golden cases to see if any have templated base URLs without explicit endpoint_template_vars.Assistant
None of the golden cases use templated URLs. Let me verify more thoroughly by searching all case input files for
{in any URL field.Assistant
No golden cases have templated URLs, and no
url.goexists in expected output. The golden suite won't be affected. Let me now search existing tests that construct specs with{in BaseURL/fields to ensure my inference doesn't change their expectations.Assistant
Let me examine these existing tests with templated BaseURLs to make sure my change doesn't break their expectations.
Assistant
This test uses
New(apiSpec, outputDir)and has explicit EndpointTemplateVars [shop, api_version]. My function preserves these (they match the BaseURL and GraphQLEndpointPath). So no change. Good.Let me check the other two at lines 11465 and 11913.
Assistant
This test has explicit
EndpointTemplateVars: []string{"domain"}matching the BaseURL. My function preserves it. Let me check line 11913.Assistant
All existing templated-URL tests have explicit
EndpointTemplateVarswhich my change preserves. Let me run these specific tests to confirm they pass.Assistant
All pass. Now let me run the broader generator test suite (excluding the govulncheck-gated compile tests which fail due to the env). Let me run with
-shortto skip the slow compile tests and confirm nothing else breaks.Assistant
Only the govulncheck-gated test fails (pre-existing). Let me confirm the list of all failing tests is just govulncheck-related.
Assistant
Only
TestGenerateWithNoAuthfails, solely due to the pre-existing govulncheck stdlib vuln. Let me rungo veton the changed packages.Assistant
Everything is clean. Let me review the final diff.
Assistant
The diff looks good. Let me confirm the
cmdgenerate path usesgenerator.Newso the inference applies there too.Assistant
All generation paths go through
generator.New. Let me check the generate command flow inroot.goto understand validation ordering relative toNew.Assistant
The flow confirms validation/generation use the same populated specification (New → inference → Generate → Validate). My implementation satisfies the contract. Let me do a final full build to confirm everything compiles.
Assistant
Let me verify no temporary test files remain and confirm the final git status.
Assistant
Only the two intended files are modified. Let me run the graphql parser tests as well, since GraphQL specs use
GraphQLEndpointPath.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.