-
Notifications
You must be signed in to change notification settings - Fork 303
feat(go): handle usernameOmit/passwordOmit in dynamic snippets generator #14410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2fe058d
13cbed4
f9bf5c9
1ec751e
b000b60
5dc3a3f
908798f
f1c45dd
b21f402
486e150
cc1c8be
cd34294
f91ea26
54efba0
e3abf1d
2707971
a562c72
431cff2
0cb4dfe
6166895
fe641c4
3f6e4af
83e8b29
e959952
b2f7b36
9ddc97d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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<string, unknown>; | ||||||||||||||||||||||||||||||
|
devin-ai-integration[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||
| 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) | ||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||
|
Comment on lines
+392
to
+398
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Empty string passed for omitted auth field produces incorrect snippet When only one of
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Go SDK's Returning The other generators (PHP, Ruby, C#) can skip individual named arguments because they use keyword/named params, but Go uses positional args.
devin-ai-integration[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||
| go.codeblock((writer) => { | ||||||||||||||||||||||||||||||
| writer.writeNode( | ||||||||||||||||||||||||||||||
| go.invokeFunc({ | ||||||||||||||||||||||||||||||
| func: go.typeReference({ | ||||||||||||||||||||||||||||||
| name: "WithBasicAuth", | ||||||||||||||||||||||||||||||
| importPath: this.context.getOptionImportPath() | ||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||
| arguments_ | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||
|
devin-ai-integration[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| private getConstructorBaseUrlArg({ | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Prohibited
as unknown as Xtype assertion pattern violates repository rulesLine 389 uses
auth as unknown as Record<string, unknown>, which is explicitly prohibited by CLAUDE.md: "Never useas anyoras unknown as X. These are escape hatches that bypass the type system entirely. If the types don't line up, fix the types." This unsafe cast is used becauseusernameOmit/passwordOmitaren't part of theFernIr.dynamic.BasicAuthtype. The proper fix is to extend the dynamic IR type to include these fields, which would also resolve the serialization issue in BUG-0001.Was this helpful? React with 👍 or 👎 to provide feedback.