feTS
feTS copied to clipboard
Server variables in the open api spec fail to typecheck on createClient with endpoint
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
});
Any word on this? I'd love to stop using as any on my endpoint..