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:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /cli-printing-press, current file: none) bash-$
- Assistant
I'll start by exploring the repository to understand its structure and locate the relevant files. Let's first get an overview.
- Assistant
Let me explore the repository structure more to understand the codebase and find the relevant files.
- Assistant
Let me look at the spec package, which is mentioned in the issue.
- Assistant
Let me look for the spec package specifically.
- Assistant
Let me explore the internal/spec directory.
- Assistant
Let me look at the spec.go file to understand the structure.
- Assistant
Let me look at the spec struct definition to understand the fields mentioned in the issue.
- Assistant
Let me also look at the resource, endpoint, and subresource BaseURL fields.
- Assistant
Let me look at the spec struct and the tier base URLs.
- Assistant
Now let me look at the Generator and its New function.
- Assistant
Let me understand the structure better by looking at the Generator and spec files.
- Assistant
Let me look at more of the Generator.New function and understand the spec structure for URL fields.
- Assistant
Let me look at the full Generator.New function to see where it returns.
- Assistant
Let me find where the
Newfunction returns. - Assistant
Let me see around line 565 to understand the return at the end of New():
- Assistant
Now I understand the structure. The issue asks us to create a method
InferEndpointTemplateVarsFromBaseURLson theAPISpectype ininternal/spec/spec.gothat scans various URL fields for{PLACEHOLDER}tokens and appends them toEndpointTemplateVars.Let me also look at the Resource and Endpoint types to understand the full structure.
- Assistant
Let me look at the Resource and Endpoint structs to understand the URL-bearing fields.遍历所有 URL-bearing 字段,保留显式变量及其顺序,追加每个新发现的占位符名称,并使 map 遍历具有确定性排序。
- Assistant
Let me look at the Resource and Endpoint structs.
- Assistant
Now let me look at the spec_test.go to see if there are any existing tests related to EndpointTemplateVars.
- Assistant
Let me check how EndpointTemplateVars is populated in the codebase.
- Assistant
Let me look at the existing function
EndpointTemplateDefaultandIsEndpointTemplateVarto understand how EndpointTemplateVars is used. - Assistant
Now I need to understand the full picture. Let me look at the test file to see existing patterns.
- Assistant
Now let me understand the existing placeholder extraction logic in the OpenAPI parser to learn the pattern:
- Assistant
Let me see the rest of
mergeServerTemplatePlaceholders. - Assistant
Now let me check if there are any existing tests that specifically test the
Newfunction in the generator: - Assistant
Let me look at the
templateVarPatternregex in the spec package (if it exists): - Assistant
Good. I can see there's a regex at line 1965 that matches placeholders. Let me check its definition:
- Assistant
Now let me look at the generator test to understand what happens with EndpointTemplateVars:
- Assistant
Let me look at the imports and the end of the spec.go file to understand where to add the new method:
- Assistant
Let me check the end of the spec.go file to find a good place to add the new method:
- Assistant
Now I have all the information I need. Let me look at the existing tests to understand what the tests expect:
- Assistant
Now I understand the codebase. Let me implement the
InferEndpointTemplateVarsFromBaseURLsmethod. I'll need to:- Use the existing
pathParamReregex to extract placeholders from URL fields - Scan
BaseURL,BasePath,GraphQLEndpointPath, tier base URLs, and resource/endpoint/subresource base URLs - Preserve existing
EndpointTemplateVarsentries and their order - Append each newly discovered placeholder once
- Use deterministic ordering when traversing maps
Let me find the right place to add the method, near the existing
EndpointTemplateVars-related functions: - Use the existing
- Assistant
Now I'll add the
InferEndpointTemplateVarsFromBaseURLsmethod after theIsEndpointTemplateVarfunction. Let me add it: - Assistant
I need to check if
sortis already imported in spec.go: - Assistant
I see that
sortis not imported. I need to add it to the imports. Let me also check thatpathParamReis accessible (it's at line 1965): - Assistant
Now let me add the
sortimport and the method. First, addsortto imports: - Assistant
The edit duplicated the imports. Let me fix this:
- Assistant
Good. Now let me find the exact line number of
IsEndpointTemplateVarafter the edit: - Assistant
Now let me find the closing brace of
IsEndpointTemplateVar: - Assistant
Now I'll add the new method after line 278 (the closing brace of
IsEndpointTemplateVar): - Assistant
Good, the method is added. Now let me verify it compiles:
- Assistant
Let me set up the Go environment properly.
- Assistant
The Go version is 1.26.4, which is very new. Let me check if GOPATH or GOMODCACHE are set.
- Assistant
Let me set up the Go environment variables:
- Assistant
Need to set HOME too.
- Assistant
Good, the spec package compiles. Now I need to call
InferEndpointTemplateVarsFromBaseURLsfromGenerator.Newbefore it returns. Let me look at the generator code again: - Assistant
I need to add the call to
s.InferEndpointTemplateVarsFromBaseURLs()right beforereturn g. Let me add it: - Assistant
Good. Now let me verify the generator package compiles:
- Assistant
Both packages compile. Now let me create a test script to verify the behavior:
- Assistant
Let me run the test script:
- Assistant
I can't use internal packages from outside. Let me create a test within the spec package:
- Assistant
Now let me run the tests:
- Assistant
All tests pass. Now let me clean up the temporary test file and run the existing spec tests to make sure I didn't break anything.
- Assistant
Good, all existing tests pass. Now let me run the generator tests to make sure my change to
Generator.Newdoesn't break anything: - Assistant
The only failure is
TestGenerateWithNoAuthwhich fails due togovulncheckfinding a Go standard library vulnerability (GO-2026-5856) - this is a pre-existing environment issue, not related to my changes. Let me verify by running the EndpointTemplateVars-related tests specifically: - Assistant
All EndpointTemplateVars-related tests pass. Let me also run some more tests to make sure I haven't broken anything:
- Assistant
This failure is a pre-existing environment issue (Go 1.26.4 vulnerability), not related to my changes. Let me verify by reverting my changes temporarily and running the same test:
- Assistant
Confirmed - the test was already failing before my changes. Let me restore my changes:
- Assistant
Let me look at the EndpointTemplateVars test to see how it creates specs:
- Assistant
Let me look at the
shopifyTemplateVarsTestSpec()function: - Assistant
Let me look at the shopifyTemplateVarsTestSpec function to understand how the test sets EndpointTemplateVars:
- Assistant
Let me also look at the
TestGenerateNoEndpointTemplateVarsByteCompattest to check how it's structured: - Assistant
I need to check if the loops.yaml fixture has any placeholders in its URL fields:
- Assistant
Good - no placeholders in loops.yaml. Let me run that specific test to confirm:
- Assistant
All EndpointTemplateVars-related tests pass. Let me now also verify with a comprehensive run of generator tests excluding the pre-existing govulncheck failure:
- Assistant
All tests pass. Let me verify the final state of my changes:
- Assistant
Let me now run a broader set of tests to make sure nothing is broken:
- Assistant
Bash is trying to expand the
!character. Let me use single quotes or different approach. - Assistant
All generator tests pass (except the pre-existing govulncheck one). Let me also run all spec tests one more time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →