Generator: emit resolveBaseURL when URL fields contain placeholders When an API…
- User
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. - Assistant
I'll inspect the spec package and generator to see how URL placeholders and
EndpointTemplateVarsare handled today. - Assistant
Implementing placeholder inference and wiring it into
Generator.New. - Assistant
Implemented placeholder inference for URL-bearing spec fields and wired it into generator construction.
InferEndpointTemplateVarsFromBaseURLs(internal/spec/spec.go)Scans these fields for
{placeholder}tokens (same regex as the generatedbuildURLhelper and OpenAPI parser):BaseURL,BasePath,GraphQLEndpointPath- Tier
BaseURLs (sorted tier names) - Resource, endpoint, and subresource
BaseURLs (sorted keys, recursive)
Behavior:
- Preserves existing
EndpointTemplateVarsentries and their order - Appends each newly discovered name once, in left-to-right URL order within each scan pass
- Uses sorted map keys so repeated calls are deterministic
Generator.New(internal/generator/generator.go)Calls
s.InferEndpointTemplateVarsFromBaseURLs()before returning, so:- Callers see the inferred list immediately on
gen.Spec.EndpointTemplateVars
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.