Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -33,6 +33,7 @@ export const baseGoCustomConfigSchema = z.strictObject({
offsetSemantics: z.enum(["item-index", "page-index"]).optional(),
omitFernHeaders: z.boolean().optional(),
includePlatformHeaders: z.boolean().optional(),
allowUserAgentAppInfo: z.boolean().optional(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

maxRetries: z.number().int().min(0).optional(),
retryStatusCodes: z.optional(z.enum(["legacy", "recommended"]))
});
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 @@ -40,6 +40,7 @@ func run(config *cmd.Config, coordinator *coordinator.Client) ([]*generator.File
config.OmitEmptyRequestWrappers,
config.OmitFernHeaders,
config.IncludePlatformHeaders,
config.AllowUserAgentAppInfo,
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 @@ -40,6 +40,7 @@ func run(config *cmd.Config, coordinator *coordinator.Client) ([]*generator.File
config.OmitEmptyRequestWrappers,
config.OmitFernHeaders,
config.IncludePlatformHeaders,
config.AllowUserAgentAppInfo,
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 @@ -70,6 +70,7 @@ type Config struct {
OmitEmptyRequestWrappers bool
OmitFernHeaders bool
IncludePlatformHeaders bool
AllowUserAgentAppInfo bool
Organization string
CoordinatorURL string
CoordinatorTaskID string
Expand Down Expand Up @@ -247,6 +248,7 @@ func newConfig(configFilename string) (*Config, error) {
OmitEmptyRequestWrappers: *customConfig.OmitEmptyRequestWrappers,
OmitFernHeaders: *customConfig.OmitFernHeaders,
IncludePlatformHeaders: *customConfig.IncludePlatformHeaders,
AllowUserAgentAppInfo: *customConfig.AllowUserAgentAppInfo,
Organization: config.Organization,
AlwaysSendRequiredProperties: *customConfig.AlwaysSendRequiredProperties,
Whitelabel: config.Whitelabel,
Expand Down Expand Up @@ -317,6 +319,7 @@ type customConfig struct {
OmitEmptyRequestWrappers *bool `json:"omitEmptyRequestWrappers,omitempty"`
OmitFernHeaders *bool `json:"omitFernHeaders,omitempty"`
IncludePlatformHeaders *bool `json:"includePlatformHeaders,omitempty"`
AllowUserAgentAppInfo *bool `json:"allowUserAgentAppInfo,omitempty"`
ClientName string `json:"clientName,omitempty"`
ClientConstructorName string `json:"clientConstructorName,omitempty"`
ImportPath string `json:"importPath,omitempty"`
Expand Down Expand Up @@ -550,6 +553,9 @@ func applyCustomConfigDefaultsForV1(customConfig *customConfig) *customConfig {
if customConfig.IncludePlatformHeaders == nil {
customConfig.IncludePlatformHeaders = gospec.Ptr(false)
}
if customConfig.AllowUserAgentAppInfo == nil {
customConfig.AllowUserAgentAppInfo = gospec.Ptr(false)
}
if customConfig.UnionVersion == "" {
customConfig.UnionVersion = "v1"
}
Expand Down
25 changes: 25 additions & 0 deletions generators/go/internal/generator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Config struct {
OmitEmptyRequestWrappers bool
OmitFernHeaders bool
IncludePlatformHeaders bool
AllowUserAgentAppInfo bool
Organization string
Version string
IRFilepath string
Expand All @@ -51,6 +52,28 @@ type Config struct {
ModuleConfig *ModuleConfig
}

// userAgentConfig collapses the User-Agent-related generator flags into a
// single value so they can be threaded through the file writers without adding
// yet another positional boolean parameter.
type userAgentConfig struct {
// omitFernHeaders suppresses all Fern platform headers, including the
// User-Agent, when true.
omitFernHeaders bool
// includePlatformHeaders emits the structured, runtime-computed User-Agent
// header (os/arch/Go runtime) when true.
includePlatformHeaders bool
// allowUserAgentAppInfo emits the opt-in appInfo client option whose product
// token is appended to whatever User-Agent the SDK would otherwise send.
allowUserAgentAppInfo bool
}

// emitsAppInfo reports whether the opt-in User-Agent appInfo feature should emit
// any generated code. It is on only when the flag is enabled and the User-Agent
// is not suppressed by omitFernHeaders (which drops all Fern platform headers).
func (c userAgentConfig) emitsAppInfo() bool {
return c.allowUserAgentAppInfo && !c.omitFernHeaders
}

// ModuleConfig represents the configuration used to generate
// a go.mod and go.sum.
type ModuleConfig struct {
Expand Down Expand Up @@ -86,6 +109,7 @@ func NewConfig(
omitEmptyRequestWrappers bool,
omitFernHeaders bool,
includePlatformHeaders bool,
allowUserAgentAppInfo bool,
organization string,
version string,
irFilepath string,
Expand Down Expand Up @@ -123,6 +147,7 @@ func NewConfig(
OmitEmptyRequestWrappers: omitEmptyRequestWrappers,
OmitFernHeaders: omitFernHeaders,
IncludePlatformHeaders: includePlatformHeaders,
AllowUserAgentAppInfo: allowUserAgentAppInfo,
Version: version,
IRFilepath: irFilepath,
SnippetFilepath: snippetFilepath,
Expand Down
15 changes: 5 additions & 10 deletions generators/go/internal/generator/file_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ type fileWriter struct {
serverURLVariables bool
exportAllRequestsAtRoot bool
omitEmptyRequestWrappers bool
omitFernHeaders bool
includePlatformHeaders bool
userAgent userAgentConfig
unionVersion UnionVersion
customPagerName string
scope *gospec.Scope
Expand Down Expand Up @@ -151,8 +150,7 @@ func newFileWriter(
serverURLVariables bool,
exportAllRequestsAtRoot bool,
omitEmptyRequestWrappers bool,
omitFernHeaders bool,
includePlatformHeaders bool,
userAgent userAgentConfig,
unionVersion UnionVersion,
customPagerName string,
types map[common.TypeId]*ir.TypeDeclaration,
Expand Down Expand Up @@ -203,8 +201,7 @@ func newFileWriter(
serverURLVariables: serverURLVariables,
exportAllRequestsAtRoot: exportAllRequestsAtRoot,
omitEmptyRequestWrappers: omitEmptyRequestWrappers,
omitFernHeaders: omitFernHeaders,
includePlatformHeaders: includePlatformHeaders,
userAgent: userAgent,
unionVersion: unionVersion,
customPagerName: customPagerName,
scope: scope,
Expand Down Expand Up @@ -461,8 +458,7 @@ func (f *fileWriter) GenerateGetterSetterTestFile() (*File, error) {
f.serverURLVariables,
f.exportAllRequestsAtRoot,
f.omitEmptyRequestWrappers,
f.omitFernHeaders,
f.includePlatformHeaders,
f.userAgent,
f.unionVersion,
f.customPagerName,
f.types,
Expand Down Expand Up @@ -997,8 +993,7 @@ func (f *fileWriter) clone() *fileWriter {
f.serverURLVariables,
f.exportAllRequestsAtRoot,
f.omitEmptyRequestWrappers,
f.omitFernHeaders,
f.includePlatformHeaders,
f.userAgent,
f.unionVersion,
f.customPagerName,
f.types,
Expand Down
108 changes: 76 additions & 32 deletions generators/go/internal/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,11 @@ func (g *Generator) generateModelTypes(ir *fernir.IntermediateRepresentation, mo
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
ir.Types,
Expand Down Expand Up @@ -337,8 +340,11 @@ func (g *Generator) generate(ir *fernir.IntermediateRepresentation, mode Mode) (
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
nil,
Expand Down Expand Up @@ -368,8 +374,11 @@ func (g *Generator) generate(ir *fernir.IntermediateRepresentation, mode Mode) (
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
nil,
Expand Down Expand Up @@ -423,8 +432,11 @@ func (g *Generator) generate(ir *fernir.IntermediateRepresentation, mode Mode) (
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
ir.Types,
Expand Down Expand Up @@ -466,8 +478,11 @@ func (g *Generator) generate(ir *fernir.IntermediateRepresentation, mode Mode) (
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
ir.Types,
Expand Down Expand Up @@ -500,8 +515,11 @@ func (g *Generator) generate(ir *fernir.IntermediateRepresentation, mode Mode) (
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
ir.Types,
Expand Down Expand Up @@ -540,8 +558,11 @@ func (g *Generator) generate(ir *fernir.IntermediateRepresentation, mode Mode) (
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
ir.Types,
Expand Down Expand Up @@ -571,8 +592,11 @@ func (g *Generator) generate(ir *fernir.IntermediateRepresentation, mode Mode) (
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
ir.Types,
Expand Down Expand Up @@ -605,8 +629,11 @@ func (g *Generator) generate(ir *fernir.IntermediateRepresentation, mode Mode) (
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
ir.Types,
Expand Down Expand Up @@ -638,8 +665,11 @@ func (g *Generator) generate(ir *fernir.IntermediateRepresentation, mode Mode) (
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
ir.Types,
Expand Down Expand Up @@ -699,8 +729,11 @@ func (g *Generator) generate(ir *fernir.IntermediateRepresentation, mode Mode) (
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
ir.Types,
Expand Down Expand Up @@ -862,8 +895,11 @@ func (g *Generator) generateRootService(
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
ir.Types,
Expand Down Expand Up @@ -918,8 +954,11 @@ func (g *Generator) generateService(
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
ir.Types,
Expand Down Expand Up @@ -977,8 +1016,11 @@ func (g *Generator) generateServiceWithoutEndpoints(
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
ir.Types,
Expand Down Expand Up @@ -1031,8 +1073,11 @@ func (g *Generator) generateRootServiceWithoutEndpoints(
g.config.ServerURLVariables,
g.config.ExportAllRequestsAtRoot,
g.config.OmitEmptyRequestWrappers,
g.config.OmitFernHeaders,
g.config.IncludePlatformHeaders,
userAgentConfig{
omitFernHeaders: g.config.OmitFernHeaders,
includePlatformHeaders: g.config.IncludePlatformHeaders,
allowUserAgentAppInfo: g.config.AllowUserAgentAppInfo,
},
g.config.UnionVersion,
g.config.CustomPagerName,
ir.Types,
Expand Down Expand Up @@ -1408,8 +1453,7 @@ func newClientTestFile(
true,
false,
false,
false,
false,
userAgentConfig{},
UnionVersionUnspecified,
"",
nil,
Expand Down
Loading