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 fields and
EndpointTemplateVarsare defined today. - Assistant
Implementing placeholder inference in
spec.goand wiring it intoGenerator.New. - Assistant
Adding a generator test to verify inference from a templated base URL produces
buildURL. - Assistant
Implemented placeholder inference for URL-bearing spec fields.
InferEndpointTemplateVarsFromBaseURLs(internal/spec/spec.go)Scans these fields in order, using the same
{name}regex as the generatedbuildURLhelper:BaseURL,BasePath,GraphQLEndpointPath- Tier
BaseURLs (sorted tier names) - Resource / endpoint / subresource
BaseURLs (sorted map keys, recursive)
Behavior:
- Keeps existing
EndpointTemplateVarsand their order - Appends each newly discovered placeholder once (left-to-right within each URL)
- No-op on nil receiver
Generator.New(internal/generator/generator.go)Calls
s.InferEndpointTemplateVarsFromBaseURLs()before returning, so inference runs before validation/generation and callers see populatedEndpointTemplateVarsimmediately.Tests
TestInferEndpointTemplateVarsFromBaseURLsin — spec-level, preservation/dedup, tier/resource traversal, nil receiver
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.