diff --git a/generators/go-v2/dynamic-snippets/src/EndpointSnippetGenerator.ts b/generators/go-v2/dynamic-snippets/src/EndpointSnippetGenerator.ts index bea9872d9e25..bac443e4ee64 100644 --- a/generators/go-v2/dynamic-snippets/src/EndpointSnippetGenerator.ts +++ b/generators/go-v2/dynamic-snippets/src/EndpointSnippetGenerator.ts @@ -356,7 +356,7 @@ export class EndpointSnippetGenerator { } switch (auth.type) { case "basic": - return values.type === "basic" ? [this.getConstructorBasicAuthArg({ auth, values })] : []; + return values.type === "basic" ? this.getConstructorBasicAuthArgs({ auth, values }) : []; case "bearer": return values.type === "bearer" ? [this.getConstructorBearerAuthArg({ auth, values })] : []; case "header": @@ -378,27 +378,37 @@ export class EndpointSnippetGenerator { this.context.errors.add({ severity: Severity.Warning, message }); } - private getConstructorBasicAuthArg({ + private getConstructorBasicAuthArgs({ auth, values }: { auth: FernIr.dynamic.BasicAuth; values: FernIr.dynamic.BasicAuthValues; - }): go.AstNode { - return go.codeblock((writer) => { - writer.writeNode( - go.invokeFunc({ - func: go.typeReference({ - name: "WithBasicAuth", - importPath: this.context.getOptionImportPath() - }), - arguments_: [ - go.TypeInstantiation.string(values.username), - go.TypeInstantiation.string(values.password) - ] - }) - ); - }); + }): go.AstNode[] { + // usernameOmit/passwordOmit may exist in newer IR versions + const authRecord = auth as unknown as Record; + const usernameOmitted = !!authRecord.usernameOmit; + const passwordOmitted = !!authRecord.passwordOmit; + if (usernameOmitted && passwordOmitted) { + return []; + } + const arguments_: go.AstNode[] = [ + go.TypeInstantiation.string(usernameOmitted ? "" : values.username), + go.TypeInstantiation.string(passwordOmitted ? "" : values.password) + ]; + return [ + go.codeblock((writer) => { + writer.writeNode( + go.invokeFunc({ + func: go.typeReference({ + name: "WithBasicAuth", + importPath: this.context.getOptionImportPath() + }), + arguments_ + }) + ); + }) + ]; } private getConstructorBaseUrlArg({ diff --git a/generators/go/sdk/versions.yml b/generators/go/sdk/versions.yml index bc3aebfc573b..8b416a3c07af 100644 --- a/generators/go/sdk/versions.yml +++ b/generators/go/sdk/versions.yml @@ -1,4 +1,16 @@ # yaml-language-server: $schema=../../../fern-versions-yml.schema.json +- version: 1.34.9 + changelogEntry: + - summary: | + Support omitting username or password from basic auth in dynamic + snippets when configured via `usernameOmit`/`passwordOmit` in the IR. + When one field is omitted, an empty string is passed for that positional + argument. When both are omitted, the `WithBasicAuth` call is skipped + entirely. + type: feat + createdAt: "2026-04-16" + irVersion: 66 + - version: 1.34.8 changelogEntry: - summary: |