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
Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me look at the spec.go file mentioned in the issue.
Assistant
Let me look at the structure around the APISpec, particularly the tier, resource, endpoint, subresource definitions.
Assistant
Now let me look at the Resource and Endpoint structs:
Assistant
Now let me look at the TierConfig and existing placeholder extraction patterns:
Assistant
Now let me find the
Generator.Newfunction mentioned in the evaluation contract:Assistant
Let me find where the
Newfunction ends and look for existing placeholder inference logic:Assistant
Let me look at how placeholders are extracted from URLs elsewhere (regex patterns):
Assistant
Let me check how the spec traverses maps deterministically elsewhere:
Assistant
Let me see how the codebase handles deterministic map traversal for resources:
Assistant
No usage of
slices.Sorted/slices.Keys. Let me check what Go version functions are available. The codebase usessort.Stringsfor determinism. I'll useslices.Sorted(slices.Keys(...))if available, but to be safe and consistent with the codebase, I'll usesort.Stringson collected keys.Actually, let me check how the generator traverses resources deterministically. Let me look at the generator's traversal patterns.
Assistant
Let me look at the spec_test.go to understand expectations and the existing test for EndpointTemplateVars:
Assistant
Let me look at the validation code for EndpointTemplateVars and placeholder-related validation:
Assistant
Now I have a clear understanding. Let me look at the imports in generator.go to add the spec import check:
Assistant
Now let me add the
InferEndpointTemplateVarsFromBaseURLsmethod to spec.go, right afterIsEndpointTemplateVar:Assistant
Now let me add the new method after
IsEndpointTemplateVar:Assistant
Let me add a blank line between the new function and
EffectiveTier:Assistant
Now let me add the call in
Generator.New. Let me view the end ofNew:Assistant
Now let me add the call to
InferEndpointTemplateVarsFromBaseURLsinNewbefore the return:Assistant
Now let me verify the build compiles:
Assistant
Build passes. Now let me write a temporary test to reproduce and verify the inference behavior:
Assistant
The test passes. Let me also verify that
Generator.Newinvokes it by writing a test in the generator package:Assistant
Both tests pass. Now let me run the existing spec and generator tests to make sure nothing is broken:
Assistant
The failure is a pre-existing
govulncheckgate failing due to a Go standard library vulnerability (crypto/tls@go1.26.4 needs go1.26.5) — environmental and unrelated to my change. Let me confirm by stashing my changes and running the same test:Assistant
Confirmed pre-existing and unrelated. Let me run the rest of the generator tests excluding the govulncheck-gated ones to ensure my change doesn't break golden-output comparisons:
Assistant
Let me look at the byte-compat test to make sure my change doesn't alter it:
Assistant
The byte-compat test passed, confirming that specs without placeholders in URLs remain unchanged. Now let me run the broader generator test suite, excluding the govulncheck-gated tests, to be thorough:
Assistant
Let me check for any test fixtures that have
{placeholders in BaseURL but expect no url.go (which would now change behavior):Assistant
Let me check these tests. Line 11913 — let me look at the test around there, since it uses BaseURL with
{shop}placeholder. It may already set EndpointTemplateVars explicitly or expect inference. Let me look.Assistant
This test already sets
EndpointTemplateVars = []string{"shop"}explicitly. My change would re-appendshopbut since it's already in seen, nothing changes. And it also adds the resource BaseURL{shop}.storefront-api...—shopalready seen. So no change. Good.Let me check the test at line 11913 again — wait that's the one I just saw (line 11913 is
apiSpec.BaseURL = "https://{shop}.storefront-api...— no, that's the storefront BaseURL in resource). Actually line 11913 isBaseURL: "https://{shop}.storefront-api.example.com/v1",— it's the storefront resource BaseURL. It already sets EndpointTemplateVars = []string{"shop"}. So inference adds nothing new. Good.Let me check lines 11152 and 11465.
Assistant
These tests set
EndpointTemplateVarsexplicitly and the placeholders in URLs are already present, so my inference adds nothing new. Now let me clean up the temporary test files and run the full spec test suite plus a broader build:Assistant
Let me review the final diff:
Assistant
Let me check whether
Validatechecks for undeclared placeholders in BaseURL (which could matter for the inference timing):Assistant
Let me run a broader set of generator tests to confirm my change doesn't introduce new failures (skipping the known govulncheck-gated tests):
Assistant
Let me check whether
Generateruns the validation gates (govulncheck):Assistant
Let me run the validate tests and a final targeted run of generation tests that exercise builds:
Assistant
All relevant tests pass. Let me verify the temp test files are removed and do a final review:
Assistant
The temporary test files are removed, and only the two intended source changes remain. Let me do a final build check of the entire module:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.