Fix endpoint type inference for OpenAPI server variable templates#3664
Merged
Fix endpoint type inference for OpenAPI server variable templates#3664
Conversation
Add utility types ServerVariableType and ResolveServerUrl that transform
OpenAPI server URL templates with {variable} patterns into proper TypeScript
template literal types. Variables with enum constraints produce union types,
while unconstrained variables become string.
Update ClientOptionsWithStrictEndpoint to infer server variables alongside
the URL and apply ResolveServerUrl to produce the correct endpoint type.
Add test fixture and type test for the server variables scenario.
Co-authored-by: ardatan <20847995+ardatan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix server variable typecheck in open api client
Fix endpoint type inference for OpenAPI server variable templates
Mar 20, 2026
Contributor
💻 Website PreviewThe latest changes are available as preview in: https://abaef2e4.fets.pages.dev |
Contributor
✅ Benchmark Results |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an OAS document uses server variable templates (e.g.
https://{username}.server.com:{port}/{version}), theendpointoption oncreateClientwas typed as the raw literal string"https://{username}.server.com:{port}/{version}"— which no real URL can satisfy, forcing users to use type assertions.Changes
ClientOptionsWithStrictEndpoint— updated the server object pattern to also infer thevariables?field alongsideurl, then appliesResolveServerUrlto produce a proper template literal type instead of the raw URL template string.ServerVariableType<TVarName, TVariables>— new utility type that maps a variable name to its TypeScript type: a union of itsenumvalues if present,stringotherwise.ResolveServerUrl<TUrl, TVariables>— new utility type that recursively replaces{varName}tokens in a URL string with the correspondingServerVariableType.Result
Original prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.