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 entry point to see how URL fields and
EndpointTemplateVarsare defined today. - Assistant
Implementing placeholder inference and wiring it into
Generator.NewandParse. - Assistant
Adding tests for the inference behavior:
- Assistant
The test expectation was wrong — resources are scanned in sorted name order (
alphabeforezebra), so I'll fix it. - Assistant
Implemented placeholder inference for URL-bearing spec fields.
InferEndpointTemplateVarsFromBaseURLs(internal/spec/spec.go)Scans these fields for
{placeholder}tokens (using the same identifier regex as the OpenAPI parser and generatedbuildURL):BaseURL,BasePath,GraphQLEndpointPath- Tier
BaseURLs (sorted tier names) - Resource, endpoint, and subresource
BaseURLs (sorted map keys, recursive)
Behavior:
- Preserves existing
EndpointTemplateVarsentries and their order - Appends each newly discovered name once
- Left-to-right order within each URL string
Call sites
Generator.New— inference runs before return, so callers see populatedEndpointTemplateVarsimmediately and generation uses the same spec.ParseBytes— inference runs afterexpandOperations()and before validation, so YAML specs with templated URLs get resolver support without an explicitendpoint_template_varslist.
Tests
TestInferEndpointTemplateVarsFromBaseURLs— preservation, tier/resource scanning, deduplicationTestParseInfersEndpointTemplateVarsFromBaseURLs— parse-time inferenceTestGeneratorNewInfersEndpointTemplateVarsFromBaseURLs—Generator.Newinference producesurl.gowithbuildURLand a buildable client
A spec like
base_url: https://{shop}withgraphql_endpoint_path: /admin/api/{api_version}/graphql.jsonnow infers["shop", "api_version"]and emits the URL resolver without hand-declaringendpoint_template_vars.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →