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
Good, there's
pathParamReat line 1965 which matches{name}placeholders. Let's look at the struct definitions for Resource, Endpoint, TierConfig, and how Resources/Tiers are stored (map or slice).Assistant
Now let's look at TierConfig and TierRoutingConfig for BaseURL fields.
Assistant
Need to add "sort" import. Let's find a good place to insert the new function - near where
pathParamReis defined, or nearHasResourceBaseURLOverride. Let's view around line 1960-1970 for pathParamRe.Assistant
Now let's insert the new function after line 1359 (before
type Endpoint struct).Assistant
Now insert the new function at line 1361.
Assistant
Now add the "sort" import.
Assistant
Import order isn't alphabetical now (sort before slices). Let's fix with gofmt/goimports.
Assistant
Now set up Go env and build.
Assistant
Build succeeds. Now let's wire this into
Generator.New.Assistant
Now let's write a quick reproduction/test script to confirm the behavior.
Assistant
Need to place the test file within the repo (internal package usage requires being under the module tree with proper path). Let's put it inside internal/spec as a temp _test-like main won't work since it's a package main. Instead create a temporary test file in internal/spec package.
Assistant
Idempotent and order preserved: explicit first, then BaseURL(shop), then tiers(proenv), then resources(region, tenant, itemregion) in sorted-key order. Let's remove the temp test file.
Assistant
Now let's run the existing test suites for spec and generator packages to make sure nothing broke.
Assistant
Confirmed this failure is pre-existing and unrelated to my change (Go toolchain vulnerability, environment issue). Let's restore my changes.
Assistant
Now let's run the rest of generator tests excluding that known-broken govulncheck-gated test, to be sure nothing else broke.
Assistant
All relevant tests pass. Now let's run the full test suite excluding the known govulncheck-related failing test to ensure broader coverage, and also check other packages that use spec/generator.
Assistant
Confirmed pre-existing failure unrelated to my change. Now let's double check
git difffor correctness and finalize.Assistant
Now let's also verify a generation-from-scratch scenario end-to-end: generate a client from a templated base URL and confirm it builds and contains buildURL (the resolver).
Assistant
Let's find
shopifyTemplateVarsTestSpecto see if it explicitly sets EndpointTemplateVars, and create a variant without it to test inference end-to-end.Assistant
Excellent, this fully validates the end-to-end contract. Now clean up the temp test file since we should not add new tests to the repo.
Assistant
Now let's double check other callers of
Generator.Newandspecloading paths (e.g., openapi parser, pipeline) to ensure no double-inference issues or unintended behavior changes.Assistant
This confirms the entry points align with the contract —
Generator.Newis the shared choke point. Now let's re-run the broader spec and generator test suites one more time to make sure everything is clean after removing temp files.Assistant
All tests pass (except the pre-existing environment-related failures unrelated to this change). Let's view the final diff once more for a sanity check.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.