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 existing code related to EndpointTemplateVars and URL fields.
- Assistant
Next I'll inspect
EndpointTemplateVars, base URL handling, and where the generator is constructed. - Assistant
rg is not available, let me use grep instead.
- Assistant
I'll inspect the spec definition and related generator logic for placeholder/base URL handling.
- Assistant
I'll examine how
Generator.Newworks and howresolveBaseURLis currently generated. - Assistant
Let me look at the Generator.New function and relevant tests about basing from URL templates.
- Assistant
I'll check project docs and recent code for any planned or partial implementation of this feature.
- Assistant
Let me look at git history for any related branch or partial work, and also look at tests that might have been added for this feature.
- Assistant
I'll read
url.go.tmpland the OpenAPI parser's template-var extraction so we can reuse that approach. - Assistant
Let me look at the url.go.tmpl and also if there are tests specifically for InferEndpointTemplateVars. Also check AGENTS.md for guidance.
- Assistant
Checking for design notes and any existing incomplete implementation of this inference.
- Assistant
Empty .entire. Let me look closer at the generator client templates for request_base_url and how tier base URLs work with placeholders. The issue says:
- Assistant
I'll implement
InferEndpointTemplateVarsFromBaseURLsand call it fromGenerator.New. Reviewing map traversal and URL field usage first. - Assistant
Let me look at how resources/maps are sorted elsewhere in the codebase for deterministic ordering.
- Assistant
There's already a
sortedKeyshelper in generator.go. Checking the end ofspec.goand nearby helpers for a good place to add the method. - Assistant
Checking whether tests already cover this function, and how
Generator.Newinteracts with related setup: - Assistant
Checking call sites for similar inference hooks and whether specs with templated base URLs currently fail generation.
- Assistant
Looking at line 1760 - let me see where Expand and Enriched are called during load.
- Assistant
Checking how OpenAPI handles per-operation server URLs and whether placeholders can be missed:
- Assistant
I'll implement the inference method, wire it into
Generator.New, and verify with a temporary script. - Assistant
Adding the inference method and the
sortimport. - Assistant
I need to fix the duplicate imports I introduced.
- Assistant
Good, imports fixed. Now add the method after IsEndpointTemplateVar.
- Assistant
I'll insert the new method after IsEndpointTemplateVar.
- Assistant
There's a duplicate return line — I'll remove it.
- Assistant
Next I'll verify the surrounding code and wire the call into
Generator.New. - Assistant
There's a duplicate
EffectiveTiersignature — fixing that next. - Assistant
I'll wire inference into
Generator.Newright at the start so callers see the inferred vars. - Assistant
I'll also invoke inference in
ParseBytesbefore validation, matching the interface contract. - Assistant
I'll add InferEndpointTemplateVarsFromBaseURLs after EnrichPathParams and before validate/Validate.
- Assistant
I'll add the call before Validate.
- Assistant
I'll write a temporary script to validate inference behavior and run targeted tests.
- Assistant
Need to rename the file without
_test.gosogo runwill execute it. - Assistant
Need to set GOPATH and GOCACHE — there's a
.gocachein the repo I can use. - Assistant
Can't import
internalfrom outside the module — I'll put a temporary test inside the package instead. - Assistant
Spec tests passed. Running the generator temp tests next.
- Assistant
All three tests passed. Removing the temporary test file before submit.
- Assistant
Restoring
.gocacheso only our source changes remain. - Assistant
Untracked
.gocachefiles are still present — cleaning those up next.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.