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
Let me start by exploring the repository structure to understand the codebase and find the relevant files mentioned in the issue description.
The issue is about:
- Creating a function
InferEndpointTemplateVarsFromBaseURLsininternal/spec/spec.go - This function should scan URL-bearing fields for
{PLACEHOLDER}tokens - It should append newly discovered placeholders to
EndpointTemplateVars - It needs to be called from
Generator.Newbefore returning
Let me start by exploring the repository structure.
- Creating a function
Assistant
Let me continue exploring the spec file and find the Generator:
Assistant
Let me continue reading the generator.go file to see the full
Newfunction and understand the structure better.Assistant
Now let me look at the rest of the
Newfunction to find where it returns:Assistant
Now I see the
Newfunction ends at around line 570 withreturn g. Let me look at the spec types more closely - I need to understand the Resource, Endpoint, and SubResource structures:Assistant
Now let me look for any existing tests related to EndpointTemplateVars and the spec to understand the testing patterns:
Assistant
Now let me look at the spec test file to understand the testing patterns:
Assistant
Let me look at the existing placeholder extraction regex patterns:
Assistant
Let me look at how the openapi parser extracts template vars:
Assistant
Now I have a good understanding of the codebase. Let me look at the template variable pattern and the merge function more closely:
Assistant
Good, I now understand the
templateVarPatternregex used to match{PLACEHOLDER}tokens. Now let me check if there's already anInferEndpointTemplateVarsFromBaseURLsfunction or similar:Assistant
Good, the function doesn't exist yet. Let me also check what the test file for spec looks like:
Assistant
Let me examine the spec_test.go to understand the test patterns:
Assistant
Now I have a good understanding of the codebase. Let me create the
InferEndpointTemplateVarsFromBaseURLsfunction ininternal/spec/spec.go. Let me first see exactly where in spec.go I should add it (near the EndpointTemplateVars related methods):Assistant
Good. Now I need to understand what URL-bearing fields exist and what the function needs to scan. According to the issue:
BaseURLBasePathGraphQLEndpointPath- Tier base URLs (in
TierRoutingConfig.Tiers[*].BaseURL) - Resource base URLs (
Resource.BaseURL) - Endpoint base URLs (
Endpoint.BaseURL) - Subresource base URLs (
Resource.SubResources[*].BaseURL)
Let me now implement the
InferEndpointTemplateVarsFromBaseURLsfunction. I'll add it after theIsEndpointTemplateVarmethod:Assistant
Now I'll add the
InferEndpointTemplateVarsFromBaseURLsfunction afterIsEndpointTemplateVar. I need to:- Define a regex pattern for
{PLACEHOLDER}tokens - Scan all URL-bearing fields
- Preserve existing explicit entries and their order
- Append each newly discovered placeholder once
- Use deterministic ordering when traversing maps
- Define a regex pattern for
Assistant
I need to provide a line range. Let me fix the range:
Assistant
The function was added. Now I need to integrate it into the
Generator.Newfunction. Let me check the generator.go file:Assistant
I need to add the call to
InferEndpointTemplateVarsFromBaseURLsin theGenerator.Newfunction. According to the issue, it should be called before the function returns, so callers can observe the inferredEndpointTemplateVarsimmediately. Let me add the call right at the beginning of the function, before any other processing:Assistant
Now let me verify the code compiles by running
go build:Assistant
Now let me run the existing tests to make sure nothing is broken:
Assistant
All spec tests pass. Now let me run the generator tests:
Assistant
modified: internal/spec/spec.go
Assistant
The failing test
TestGenerateWithNoAuthis failing due to agovulncheckvulnerability scan (GO-2026-5856 in crypto/tls), which is unrelated to my changes. This is a pre-existing environment issue with the Go standard library version.Let me verify my implementation is working correctly by creating a quick test script:
Assistant
The output shows the file was created. Now I need to run this test script to verify my implementation works correctly.
Assistant
Internal packages can't be imported from outside the module. I need to put the test file inside the module's internal directory or run it as a test within the package.
Assistant
All tests pass. Let me remove the test file I created (since the instructions say not to add new tests) and run the existing spec tests to confirm nothing is broken:
Assistant
Now let me run the full spec test suite to confirm everything still passes:
Assistant
Let me review the final changes I made:
Assistant
Let me verify the changes are complete and run a quick sanity check to make sure everything still compiles and the existing tests pass.
Assistant
Let me run the full spec test suite to confirm all existing tests pass:
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 →