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 implement this as a systemic generator/spec change, first checking repository guidance, the relevant spec/generator tests, and current worktree state.
- Assistant
rgis unavailable in this environment, so I’m using local filesystem and Git searches instead. I’ll keep the change scoped to the Printing Press generator and add focused coverage for ordering, deduplication, all URL fields, andGenerator.Newvisibility. - Assistant
The existing generated client already has a conditional URL resolver (
buildURLinurl.go), but emission depends onEndpointTemplateVars. I found the missing link: URL placeholders are never inferred, so the resolver file and related config wiring are skipped unless a spec declares variables manually. I’m adding idempotent inference at the spec layer and invoking it from both validation andGenerator.New. - Assistant
The focused tests are running now, including compiling a freshly generated CLI from a templated base URL. The implementation preserves explicit entries exactly, scans placeholders left-to-right within each field, and sorts every map key before traversal.
- Assistant
The first test attempt hit a host process-limit error while Go was compiling dependencies, not a code failure. I’ve rerun serially with cgo disabled; the cold build is still progressing without test output or failures.
- Assistant
Focused coverage passes, including the generated client build. The repository-wide suite encountered the environment’s process ceiling because many generator tests launch nested Go builds in parallel; it also exposed one unrelated pipeline assertion. I’ll still run the required build and golden verification with conservative Go parallelism, then inspect the final diff.
- Assistant
Implementation and focused verification are complete. The binary builds, inferred templated URLs generate and compile the resolver-enabled client, and the deterministic inference test passes. Golden verification could not start because this environment lacks
jq; the full suite’s failures were confined to the host process limit plus an unrelated pre-existing pipeline assertion.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.