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
Now let me find the
Generator.Newfunction and existing placeholder extraction logic.Assistant
Let me find where the
Newfunction ends (thereturn g).Assistant
Now let me look at existing placeholder extraction logic. Let me search for how
{placeholders are extracted currently.Assistant
Now let me look at the existing placeholder extraction helper,
mergeServerTemplatePlaceholders, to understand the pattern.Assistant
Now let me look at the spec_test.go to understand existing test patterns, and check the
Resourcesfield structure.Assistant
Let me check the imports in spec.go and existing helper methods around line 270.
Assistant
Now let me look at the existing test file structure and how the generator tests are set up.
Assistant
Now let me understand the full structure. Let me check what URL-bearing fields need scanning: BaseURL, BasePath, GraphQLEndpointPath, tier BaseURLs, resource/endpoint/subresource BaseURLs. Let me also check the test for
Newin the generator.Assistant
Now let me create a reproduction script to confirm the issue: a spec with
{PLACEHOLDER}in BaseURL but no EndpointTemplateVars, then check that aftergenerator.New, the EndpointTemplateVars are NOT populated (the bug).Assistant
I need to test within the module. Let me create a temp test file in the generator package.
Assistant
I've reproduced the bug. Now let me implement the
InferEndpointTemplateVarsFromBaseURLsmethod onAPISpecin spec.go, and call it fromgenerator.New.Assistant
Let me view the exact location around
IsEndpointTemplateVarto place the new method.Assistant
Now let me implement the method. First, add the
sortimport.Assistant
The sed multi-line didn't work. Let me use the edit tool.
Assistant
Now let me add the method. I'll insert it after
IsEndpointTemplateVar.Assistant
Let me simplify - remove the local
appendclosure that shadows the builtin and use the standalone helper consistently.Assistant
Now let me call this from
generator.New. Let me view theNewfunction start again and add the call.Assistant
Now let me build and run the repro test.
Assistant
Builds. Now run the repro test.
Assistant
Now let me write a more comprehensive test covering all the fields, ordering, dedup, and explicit entries preservation.
Assistant
The regex intentionally only matches identifier-style names (no hyphens), matching the existing
templateVarPatternbehavior. My test expectation was wrong. Let me fix it to reflect correct behavior.Assistant
Let me just rewrite the test file cleanly.
Assistant
Determinism works; my expected ordering was wrong (t1→c, t2→b). Let me fix.
Assistant
All my repro tests pass. Now let me clean up the repro test files and run the existing test suites for spec and generator to make sure nothing broke.
Assistant
The failure is an environmental
govulncheckgate (Go stdlib vulnerability in crypto/tls), unrelated to my change. Let me confirm it's pre-existing by checking that test and running the relevant golden-generation tests that would be affected by my change.Assistant
Confirmed pre-existing and environmental. Now let me run the golden tests that involve template vars and tier routing to ensure my change doesn't alter existing generated output.
Assistant
All template-var tests pass. Now let me run the tier routing golden tests and the openapi parser tests.
Assistant
Let me search for any spec files in testdata/catalog with
{in BaseURL to ensure my inference doesn't unexpectedly alter golden output.Assistant
Now let me run the broader golden test suite to make sure no golden output changes. Let me find golden tests.
Assistant
Let me check the
TestGenerateProjectsCompiletest to see if it covers catalog specs (which have template vars).Assistant
These fixtures (stytch, clerk, loops) parse via
spec.Parse. Let me check whether they have placeholders in BaseURL. These are already-parsed specs, so the parser populates EndpointTemplateVars. My inference would be a no-op. Let me run this test to confirm compile still works. But it builds the projects which might trigger govulncheck? No,runGoCommanddoesmod tidyandbuild ./..., not govulncheck. So it should be safe. Let me run it.Assistant
Now let me verify a spec with template-var BaseURL actually produces a buildable client (the core of the issue). Let me write a repro that generates from the shopify catalog spec.
Assistant
Let me search across all test specs for BaseURL with
{placeholders to ensure none rely on empty EndpointTemplateVars.Assistant
All these tests already declare EndpointTemplateVars explicitly, so my inference is a no-op.
Let me check line 11913 - the resource BaseURL with template var test.
Assistant
Let me search for resource/endpoint/tier BaseURL with
{placeholders in tests to ensure no test relies on empty EndpointTemplateVars.Assistant
Let me check the tier_routing_test.go to see if it has tier BaseURLs with placeholders.
Assistant
Let me check
minimalSpecto ensure its BaseURL has no placeholders.Assistant
Let me run the full generator test suite to confirm only the pre-existing environmental govulncheck failure remains.
Assistant
Only
TestGenerateWithNoAuthfails — the pre-existing environmental govulncheck gate. Let me confirm no other test failed.Assistant
Only the pre-existing environmental test fails. Now let me run the profiler tests since they consume EndpointTemplateVars.
Assistant
Now let me clean up the repro test files before submitting.
Assistant
Let me review the final diff to ensure correctness.
Assistant
Let me run gofmt and go vet on the modified files.
Assistant
gofmt wants to reformat spec.go (import ordering). Let me apply gofmt.
Assistant
gofmt reordered
sortafterslices(alphabetical). Let me run the spec and generator template-var tests once more to confirm everything still works.Assistant
Everything passes. Let me do a final review of the complete diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.