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 the codebase.
Assistant
Let me look at the spec package first.
Assistant
Let me look at the spec structure to understand the types.
Assistant
Let me look at the APISpec struct more closely, and the Resources field.
Assistant
Now let me look at the Resource, Endpoint, and SubResource structs:
Assistant
Now let me look at how placeholders are extracted from URLs. Let me search for existing functions that extract
{var}from strings.Assistant
There's a
pathParamReregex. Now let me find the Generator.New function mentioned in the issue.Assistant
Let me find where the Generator.New function ends (the return statement).
Assistant
Now let me look at the existing tests for spec to understand patterns, especially around
EndpointTemplateVars.Assistant
Let me look at how
resolveBaseURLis used in templates and config.Assistant
Let me look at the spec.go imports and the area around
IsEndpointTemplateVar.Assistant
Let me check the TierConfig struct and confirm field names.
Assistant
Let me look at the
EnrichPathParamsandenrichResourcePathParamsfunctions to mirror their traversal pattern.Assistant
Now I understand the structure well. Let me write the
InferEndpointTemplateVarsFromBaseURLsmethod. I'll add it afterIsEndpointTemplateVar.Assistant
I need to add the
sortimport. Let me view the import block and the insertion point.Assistant
Now let me add the
sortimport:Assistant
Now let me add the
InferEndpointTemplateVarsFromBaseURLsmethod afterIsEndpointTemplateVar. Let me view that area:Assistant
Now let me add the new method after
IsEndpointTemplateVar:Assistant
Now let me build the spec package to confirm it compiles:
Assistant
The spec package compiles. Now let me wire up
Generator.Newto call the inference before returning. Let me view the end ofNew:Assistant
There's a duplicate closing brace at line 572. Let me fix that:
Assistant
Now let me build the generator package and run the spec tests:
Assistant
Both packages build. Now let me write a quick test script to verify the behavior, then run existing tests.
Assistant
The function works correctly — my test expectation had the wrong tier order (sorted: enterprise before premium). Let me fix the test:
Assistant
My tests pass. Now let me remove the temporary test file and run the existing spec and generator tests to make sure nothing is broken.
Assistant
Now let me check the generator tests, which could be affected since
Newnow mutates the spec. Let me look for fixtures with templated BaseURLs but noendpoint_template_vars:Assistant
No templated base_urls in fixtures, so byte-compat is preserved. Let me also check the catalog and any other specs the generator tests use:
Assistant
The shopify catalog spec has a templated
graphql_endpoint_path. Let me check whether it declaresendpoint_template_varsexplicitly already.Assistant
The shopify spec already declares matching vars, so inference won't change anything. Now let me run the generator tests:
Assistant
The failure is a
govulncheckgate (environment Go stdlib vulnerability), unrelated to my change. Let me run the EndpointTemplateVars-related generator tests specifically to confirm they pass:Assistant
All EndpointTemplateVars tests pass. Let me confirm the govulncheck failure is pre-existing (unrelated to my change) by stashing and re-running just that test:
Assistant
Confirmed —
TestGenerateWithNoAuthfails on the unmodified codebase too (pre-existing govulncheck environment issue), unrelated to my change. Let me verify the whole repo builds:Assistant
The whole repo builds. Let me run
go veton the affected packages:Assistant
Let me check the generator test file for any inline specs with templated BaseURLs that might now be affected:
Assistant
All these tests already declare matching vars, so inference adds nothing — confirmed they pass. Let me run the broader test suite for spec, openapi, and graphql packages (excluding the env-dependent govulncheck gate):
Assistant
Let me also verify the
internal/clipackage tests pass (sinceGenerator.Newis on the generate path):Assistant
All passing. Let me review the final diff:
Assistant
I notice a missing blank line between the new
sortedKeysfunction and the existingEffectiveTierfunction. Let me fix the formatting:Assistant
gofmt didn't add a blank line. Hmm, actually gofmt does enforce blank lines between top-level declarations. Let me check the actual file content around that area.
Assistant
I need to add a blank line manually between
sortedKeysandEffectiveTier:Assistant
The blank line didn't get inserted. Let me use sed to add the blank line between line 375 and 376:
Assistant
Now let me run gofmt and rebuild to confirm everything is clean:
Assistant
gofmt clean, build clean, spec tests pass. Let me run the generator EndpointTemplateVars tests once more to confirm:
Assistant
All tests pass. Let me view the final diff once more to confirm everything is clean:
Assistant
There seem to be two blank lines before
EffectiveTier. Let me check and fix:Assistant
The implementation is complete and clean. Let me do a final verification that the whole repo still builds and gofmt is clean:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.