Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const baseGoCustomConfigSchema = z.object({
enableWireTests: z.boolean().optional(),
exportAllRequestsAtRoot: z.boolean().optional(),
customReadmeSections: z.array(CustomReadmeSectionSchema).optional(),
customPagerName: z.string().optional()
customPagerName: z.string().optional(),
oauthTokenOverride: z.boolean().optional()
});

export type BaseGoCustomConfigSchema = z.infer<typeof baseGoCustomConfigSchema>;
1 change: 1 addition & 0 deletions generators/go/cmd/fern-go-fiber/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func run(config *cmd.Config, coordinator *coordinator.Client) ([]*generator.File
config.UseReaderForBytesRequest,
config.GettersPassByValue,
config.ExportAllRequestsAtRoot,
config.OAuthTokenOverride,
config.Organization,
config.Version,
config.IrFilepath,
Expand Down
1 change: 1 addition & 0 deletions generators/go/cmd/fern-go-model/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func run(config *cmd.Config, coordinator *coordinator.Client) ([]*generator.File
config.UseReaderForBytesRequest,
config.GettersPassByValue,
config.ExportAllRequestsAtRoot,
config.OAuthTokenOverride,
config.Organization,
config.Version,
config.IrFilepath,
Expand Down
1 change: 1 addition & 0 deletions generators/go/cmd/fern-go-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func run(config *cmd.Config, coordinator *coordinator.Client) ([]*generator.File
config.UseReaderForBytesRequest,
config.GettersPassByValue,
config.ExportAllRequestsAtRoot,
config.OAuthTokenOverride,
config.Organization,
config.Version,
config.IrFilepath,
Expand Down
6 changes: 6 additions & 0 deletions generators/go/internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Config struct {
UseReaderForBytesRequest bool
GettersPassByValue bool
ExportAllRequestsAtRoot bool
OAuthTokenOverride bool
Organization string
CoordinatorURL string
CoordinatorTaskID string
Expand Down Expand Up @@ -235,6 +236,7 @@ func newConfig(configFilename string) (*Config, error) {
UseReaderForBytesRequest: *customConfig.UseReaderForBytesRequest,
GettersPassByValue: *customConfig.GettersPassByValue,
ExportAllRequestsAtRoot: *customConfig.ExportAllRequestsAtRoot,
OAuthTokenOverride: *customConfig.OAuthTokenOverride,
Organization: config.Organization,
AlwaysSendRequiredProperties: *customConfig.AlwaysSendRequiredProperties,
Whitelabel: config.Whitelabel,
Expand Down Expand Up @@ -299,6 +301,7 @@ type customConfig struct {
UseReaderForBytesRequest *bool `json:"useReaderForBytesRequest,omitempty"`
GettersPassByValue *bool `json:"gettersPassByValue,omitempty"`
ExportAllRequestsAtRoot *bool `json:"exportAllRequestsAtRoot,omitempty"`
OAuthTokenOverride *bool `json:"oauthTokenOverride,omitempty"`
ClientName string `json:"clientName,omitempty"`
ClientConstructorName string `json:"clientConstructorName,omitempty"`
ImportPath string `json:"importPath,omitempty"`
Expand Down Expand Up @@ -459,6 +462,9 @@ func applyCustomConfigDefaultsForV1(customConfig *customConfig) *customConfig {
if customConfig.ExportAllRequestsAtRoot == nil {
customConfig.ExportAllRequestsAtRoot = gospec.Ptr(false)
}
if customConfig.OAuthTokenOverride == nil {
customConfig.OAuthTokenOverride = gospec.Ptr(false)
}
if customConfig.UnionVersion == "" {
customConfig.UnionVersion = "v1"
}
Expand Down
3 changes: 3 additions & 0 deletions generators/go/internal/generator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Config struct {
UseReaderForBytesRequest bool
GettersPassByValue bool
ExportAllRequestsAtRoot bool
OAuthTokenOverride bool
Organization string
Version string
IRFilepath string
Expand Down Expand Up @@ -74,6 +75,7 @@ func NewConfig(
useReaderForBytesRequest bool,
gettersPassByValue bool,
exportAllRequestsAtRoot bool,
oauthTokenOverride bool,
organization string,
version string,
irFilepath string,
Expand Down Expand Up @@ -105,6 +107,7 @@ func NewConfig(
UseReaderForBytesRequest: useReaderForBytesRequest,
GettersPassByValue: gettersPassByValue,
ExportAllRequestsAtRoot: exportAllRequestsAtRoot,
OAuthTokenOverride: oauthTokenOverride,
Version: version,
IRFilepath: irFilepath,
SnippetFilepath: snippetFilepath,
Expand Down
1 change: 1 addition & 0 deletions generators/go/internal/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ func (g *Generator) generate(ir *fernir.IntermediateRepresentation, mode Mode) (
ir.SdkConfig,
g.config.ModuleConfig,
g.config.Version,
g.config.OAuthTokenOverride,
); err != nil {
return nil, err
}
Expand Down
19 changes: 17 additions & 2 deletions generators/go/internal/generator/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func (f *fileWriter) WriteRequestOptionsDefinition(
sdkConfig *ir.SdkConfig,
moduleConfig *ModuleConfig,
sdkVersion string,
oauthTokenOverride bool,
) error {
importPath := path.Join(f.baseImportPath, "core")
f.P("// RequestOption adapts the behavior of the client or an individual request.")
Expand Down Expand Up @@ -329,6 +330,9 @@ func (f *fileWriter) WriteRequestOptionsDefinition(
typeReferenceToGoType(authScheme.Header.ValueType, f.types, f.scope, f.baseImportPath, importPath, false),
)
}
if authScheme.Oauth != nil && oauthTokenOverride {
f.P("Token string")
}
}
for _, header := range headers {
if !shouldGenerateHeader(header, f.types) {
Expand Down Expand Up @@ -370,7 +374,7 @@ func (f *fileWriter) WriteRequestOptionsDefinition(
return err
}
f.P()
return f.writeRequestOptionStructs(auth, headers, len(idempotencyHeaders) > 0)
return f.writeRequestOptionStructs(auth, headers, len(idempotencyHeaders) > 0, oauthTokenOverride)
}

// Generate the ToHeader method.
Expand Down Expand Up @@ -417,6 +421,11 @@ func (f *fileWriter) WriteRequestOptionsDefinition(
f.P(`header.Set("`, header.Name.WireValue, `", fmt.Sprintf("`, prefix, `%v",`, value, "))")
f.P("}")
}
if authScheme.Oauth != nil && oauthTokenOverride {
f.P(`if r.Token != "" {`)
f.P(`header.Set("Authorization", "Bearer " + r.Token)`)
f.P("}")
}
}
for _, header := range headers {
valueTypeFormat := formatForValueType(header.ValueType, f.types)
Expand Down Expand Up @@ -455,7 +464,7 @@ func (f *fileWriter) WriteRequestOptionsDefinition(

f.P()

if err := f.writeRequestOptionStructs(auth, headers, len(idempotencyHeaders) > 0); err != nil {
if err := f.writeRequestOptionStructs(auth, headers, len(idempotencyHeaders) > 0, oauthTokenOverride); err != nil {
return err
}

Expand Down Expand Up @@ -493,6 +502,7 @@ func (f *fileWriter) writeRequestOptionStructs(
auth *ir.ApiAuth,
headers []*ir.HttpHeader,
asIdempotentRequestOption bool,
oauthTokenOverride bool,
) error {
if err := f.writeOptionStruct("BaseURL", "string", true, asIdempotentRequestOption); err != nil {
return err
Expand Down Expand Up @@ -557,6 +567,11 @@ func (f *fileWriter) writeRequestOptionStructs(
return err
}
}
if authScheme.Oauth != nil && oauthTokenOverride {
if err := f.writeOptionStruct("Token", "string", true, asIdempotentRequestOption); err != nil {
return err
}
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions generators/go/sdk/versions.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# yaml-language-server: $schema=../../../fern-versions-yml.schema.json

- version: 1.19.0
changelogEntry:
- summary: |
Add support for OAuth token override via the `oauthTokenOverride` config option.
When enabled, users can provide a pre-generated bearer token directly via the `WithToken`
option function, bypassing the OAuth client credentials flow.
type: feat
createdAt: "2025-12-08"
irVersion: 60

- version: 1.18.4
changelogEntry:
- summary: |
Expand Down
Loading