Repository navigation
SDK variables: optional env-var fallback (IR envVar) + support in Go/C#/Ruby/PHP generators (Twilio subaccount routing) #18048
Copy link
Copy link
Open
Description
Summary
Twilio (fern-demo/twilio-core-fern-config) needs the official-SDK "act on behalf of a subaccount" behaviour: parent-account credentials + a single client-level account SID that is substituted into every v2010 {AccountSid} path, defaulting to the parent account when not set (twilio(sid, token, { accountSid }), Client(sid, token, account_sid=), Twilio.init(sid, token, accountSid)).
Fern already has SDK variables (x-fern-sdk-variables / x-fern-sdk-variable, Fern definition variables:), but two gaps blocked using them for this:
- No fallback – a variable was always a required constructor argument. Parent-account callers would have to pass
targetAccountSidexplicitly; the official SDKs default it to the auth account SID (TWILIO_ACCOUNT_SID). - Only TypeScript, Python and Java implemented IR
variables– Go, C#, Ruby (v2) and PHP silently ignoredx-fern-sdk-variableand kept the path parameter on every method.
Design
- IR
VariableDeclaration.envVar?: string(IR 67.29.0). - Fern definition:
variables: { targetAccountSid: { type: string, env: TWILIO_ACCOUNT_SID } }; OpenAPI:x-fern-sdk-variables: { targetAccountSid: { type: string, x-fern-env: TWILIO_ACCOUNT_SID } }; bind withx-fern-sdk-variable: targetAccountSidon path params. - Generators: a string variable with
envVarbecomes an optional client option; explicit value > environment variable; if a bound endpoint is called with neither set, the SDK raises a clear "<variable>is required" error. Variables withoutenvVarstay required. Bound path parameters are removed from method signatures / request types / reference docs; one value per client (matches official Twilio semantics).
PRs
- IR/CLI: feat(cli): add env var fallback for SDK variables (VariableDeclaration.envVar) #18022 (
envVaronVariableDeclaration, Fern definitionenv, OpenAPIx-fern-env) - C#: feat(csharp): SDK variables with env var fallback in the C# SDK generator #18034 (new SDK-variable support + env fallback)
- PHP: feat(php): SDK variables with env var fallback in the PHP SDK generator #18038 (new SDK-variable support + env fallback)
- TypeScript: feat(typescript): optional SDK variables with env var fallback #18029 (optional option + env fallback)
- Java: feat(java): SDK variables with env var fallback default to System.getenv and are validated at build() #18030 (builder method +
System.getenvfallback, validated in generatedsetVariables) - Go v1 + v2: feat(go): SDK variables with env var fallback in Go v1 and Go v2 generators #18033 (
option.With<Variable>,os.Getenvfallback) - Ruby v2: feat(ruby): SDK variables with env var fallback in the Ruby v2 SDK generator #18035 (new SDK-variable support + env fallback)
- Python: blocked until
fern_fern_ir_v67==67.29.0is published to the private PyPI index (the IR publish job for 67.29.0 failed and needs a maintainer rerun;@fern-fern/ir-sdk@67.29.0on npm is fine). Implementation is ready to open once the package is there.
Follow-up (Twilio side)
- fern-demo/twilio-core-fern-config#157 adds
targetAccountSidto the core v2010 override (191{AccountSid}path params bound; account-management{Sid}paths stay explicit). - After the generator releases above, bump the pinned generator versions in that repo and regenerate/verify all 7 SDKs (TS
targetAccountSid, Pythontarget_account_sid, Java.targetAccountSid(...), Gooption.WithTargetAccountSid(...), C#ClientOptions.TargetAccountSid, Rubytarget_account_sid:, PHPtargetAccountSid:).
Not in scope: per-call override of a bound variable alongside the client default (the official SDKs' client.api.v2010.accounts(sid)... escape hatch) — Fern drops the parameter from the method once it is bound.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity