feTS icon indicating copy to clipboard operation
feTS copied to clipboard

Server variables in the open api spec fail to typecheck on createClient with endpoint

Open scamden opened this issue 9 months ago • 1 comments

Describe the bug

if the open api spec contains server variables as described here: https://learn.openapis.org/specification/servers.html#server-variables

servers:
- url: https://{username}.server.com:{port}/{version}
  variables:
    username:
      default: demo
      description: This value is assigned by the service provider.
    port:
      enum:
        - "8443"
        - "443"
      default: "8443"
    version:
      default: v1

The inferred type of as const on that schema gives us the string literal: "https://{username}.server.com:{port}/{version}" which no real endpoint can match against. Ideally the type inference would read the variables syntax and produce a typescript string literal type like:

type TEndpoint = `https://${string}.server:com:${"8443" | "443"}/${string}`

as it is I have to type assert when using

createClient<typeof theAboveSchema>({
  endpoint: `http://me.server.com:443/v1`, // won't typecheck
});

scamden avatar Mar 28 '25 19:03 scamden

Any word on this? I'd love to stop using as any on my endpoint..

scamden avatar Apr 17 '25 01:04 scamden