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
Assistant
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Let me explore the structure further to understand the codebase.
Assistant
Let me first look at the structure of the spec.go file, specifically looking for EndpointTemplateVars.
Assistant
Let me look at the TierRoutingConfig and Resource types to understand the base URL fields.
Assistant
Let me look at the Generator.New function and understand where it lives:
Assistant
Now let me look at the rest of the New function to see what it does:
Assistant
Let me look at the end of the New function:
Assistant
Now let me look for the existing related functions and any tests:
Assistant
Now let me check the test file and see existing patterns:
Assistant
Let me look at the existing tests for the generator that mention EndpointTemplateVars:
Assistant
Let me look for
resolveBaseURLmentions and where it's emitted:Assistant
Let me check the Generator.New function:
Assistant
Let me see what the
Newfunction does in entirety - I need to find where it ends:Assistant
Now let me check the existing imports and look at the test file to understand the existing tests:
Assistant
Now let me see how
validateReservedPlaceholderHostis implemented since it deals with placeholders:Assistant
Let me look at where
BaseURLetc are accessed in the spec, especially TierRouting to understand how tier. Let me write down my plan:Plan:
- Define
InferEndpointTemplateVarsFromBaseURLs()method on*APISpecininternal/spec/spec.go - It should scan:
s.BaseURLs.BasePaths.GraphQLEndpointPaths.TierRouting.Tiers[name].BaseURL(each tier)s.Resources[name].BaseURL(each resource)s.Resources[name].Endpoints[endpointName].BaseURL(each endpoint)s.Resources[name].SubResources[name].BaseURL(each subresource)
- Append each newly discovered placeholder to
s.EndpointTemplateVars, preserving existing entries and their order - Use deterministic ordering when traversing maps (sort map keys alphabetically)
- Generator.New() must invoke this method before returning
Let me check the spec_test.go to see existing test patterns and the existing EndpointTemplateVars tests:
- Define
Assistant
The
sortpackage isn't currently imported inspec.go. Let me check if it's used anywhere else in spec.go and if I need to import it:Assistant
Let me see existing test patterns for templated URLs:
Assistant
Now I have a clear understanding. Let me also examine other files that build URLs from spec to see the pattern:
Assistant
Let me also look at the existing test directory for templated URLs:
Assistant
Now let me find where Generator.New() is called:
Assistant
Let me look at the parser's merge function:
Assistant
Now let me look at the spec_test.go to find existing helper to construct test specs:
Assistant
Now I have all the context I need. Let me start implementing the changes.
First, let me create the
InferEndpointTemplateVarsFromBaseURLsmethod in spec.go:Assistant
Now I'll add the new method just after
IsEndpointTemplateVar:Assistant
The edit duplicated some lines. Let me check the file:
Assistant
Let me fix this duplicate by reverting and redoing the edit properly:
Assistant
There's broken state in the file due to a malformed edit. Let me revert and start fresh:
Assistant
Good, the file is back to original. Now let me also add the
sortimport:Assistant
I see there's a duplicate
)because of how the line range overlaps. Let me fix it:Assistant
Still needs to fix the duplicate yaml line. Let me fix it:
Assistant
The sed command removed BOTH lines because I matched the
gopkg.in/yaml.v3line and then also matched the next linegopkg.in/yaml.v3. Let me check the entire import block:Assistant
I need to add the yaml import back:
Assistant
Now the imports are correct. Now let me look at the structure where I need to add the new function:
Assistant
Now let me add the new function. I'll insert it after
IsEndpointTemplateVarand beforeEffectiveTier:Assistant
Let me verify the changes are correctly applied:
Assistant
The new function is added correctly. Now let me verify the build compiles:
Assistant
The build works. Now I need to add the call to
InferEndpointTemplateVarsFromBaseURLsinGenerator.New:Assistant
Now let me build to verify:
Assistant
Let me write a quick test to verify the implementation works correctly:
Assistant
Let me write a test file inside the spec package:
Assistant
Let me delete this temporary test file since I shouldn't add new tests to the repository:
Assistant
Now let me check the existing tests still pass:
Assistant
The failure is related to a known vulnerability scan (
govulncheck) issue — that's pre-existing and unrelated to my changes. Let me check more specific tests:Assistant
Let me check if the pipeline test failure is related to my changes:
Assistant
The pipeline test failure is pre-existing, not caused by my change. Let me also verify the TestGenerateWithNoAuth:
Assistant
Let me write a thorough manual test to verify edge cases:
Assistant
All edge cases pass. Let me clean up the test file (per instructions, I shouldn't add new tests to the repository):
Assistant
Now let me also create a small test file to test the generator.New integration:
Assistant
The integration with
Generator.Newworks as expected. Let me clean up:Assistant
Let me also do an end-to-end test by running the actual CLI to make sure generation works correctly:
Assistant
The basic generation works. Let me check the generated url.go to see if it includes templateVarEnvNames:
Assistant
Let me try a spec with placeholders:
Assistant
Excellent! The generated
url.gocorrectly includestemplateVarEnvNamesmapping with theshopplaceholder. Let me now also verify that we ensure it builds:Assistant
The generated CLI is buildable. Let me test with multiple placeholders and overrides:
Assistant
Now let me verify with the OpenAPI parser test cases:
Assistant
All openapi tests pass. Let me also verify the spec tests:
Assistant
Now let me also check the GraphQL parser test case - GraphQL specs with templated endpoints:
Assistant
All tests pass. Let me also run the broader test to be sure:
Assistant
Let me also look at the diff to verify the final changes:
Assistant
The diff looks great. Let me also verify it does not break the docstring/comments on
IsEndpointTemplateVar(which were unchanged):Assistant
Let me also do an extra check to ensure I run a specific test that includes testdata/ fixtures:
Assistant
Now let me check the existing parser test case that uses templated URLs to make sure the parser test cases still work:
Assistant
All tests pass! Let me also run a quick double check to make sure the changes work well with the docspec/graphql:
Assistant
Let me also clean up the test files I created:
Assistant
All my temporary test files have been removed. The actual changes are:
internal/spec/spec.go- AddedInferEndpointTemplateVarsFromBaseURLsmethodinternal/generator/generator.go- ModifiedNewto call the new method
Let me also do one last check on the test for tiers with templated URLs:
Assistant
Now let me look at one more edge case - if all fields are empty/nil, the result should not change:
Assistant
All edge cases work. Let me also verify the spec final state:
Assistant
Only the two files are modified. Let me also do a final check that the function name exactly matches what was specified in the issue:
Assistant
The function
InferEndpointTemplateVarsFromBaseURLsis correctly:- Defined as a method on
*APISpecininternal/spec/spec.go - Takes no parameters
- Has no return value (mutates receiver)
- Called from
Generator.Newbeforereturn g
Let me also verify all the other test files that I haven't tested:
- Defined as a method on
Assistant
The failures are pre-existing. Let me confirm the pipeline test failure is pre-existing by running it on the original code:
Assistant
Confirmed: Both pre-existing failures are not related to my changes.
Let me do a final summary of the changes:
Assistant
Assistant
No temporary test files remain. Let me also do one final check to confirm the function signature matches the interface contract:
Interface Contract (from issue):
- Type: Function
- Name:
InferEndpointTemplateVarsFromBaseURLs✓ - Path:
internal/spec/spec.go✓ - Input: (no parameters) ✓ (the receiver is not a parameter, it's a method receiver)
- 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. ✓
Evaluation Contract (from issue):
Generator.Newmust invoke placeholder inference before it returns, so callers can observe the inferredEndpointTemplateVarsimmediately and later validation/generation uses the same populated specification. ✓
Assistant
Summary
I implemented the requested feature by making two changes:
1.
internal/spec/spec.go— AddedInferEndpointTemplateVarsFromBaseURLs()method- A new method on
*APISpecthat scans every documented URL-bearing field for{PLACEHOLDER}tokens - Preserves existing explicit entries in their original order
- Appends each newly discovered name exactly once (idempotent)
- Uses sorted map keys for deterministic traversal
- Helper functions
sortedResourceNamesandsortedEndpointNamesmake map iteration order deterministic - A regex
endpointTemplateVarDiscoveryREmirrors thetemplateVarPatternused in the parser and generatedurl.go.tmplso parser-discovered and inference-discovered placeholders agree on the same names
2.
internal/generator/generator.go— ModifiedNewto invoke the inference- After the funcs map is fully populated and before
return g, the generator now callss.InferEndpointTemplateVarsFromBaseURLs() - This ensures callers can immediately observe the populated and the later calls see the same fully populated spec
- A new method on
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.