From 4a99d40295e913a463638df19a45173cbcc3adf4 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Mon, 26 May 2025 15:22:00 -0700 Subject: [PATCH 1/3] do not null slice pointers by default --- builder.go | 2 +- entry.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/builder.go b/builder.go index 29f6be8..94c40e2 100644 --- a/builder.go +++ b/builder.go @@ -318,7 +318,7 @@ func (g *Goty) parseSlice(parent *DataStruct, field reflect.Type, member *Struct } name, optional := g.parseMember(parent, field.Elem(), member) - if optional { + if optional && g.config.override(field).NullSlicePointers { name = "(null | " + name + ")" } diff --git a/entry.go b/entry.go index b023980..e4fcf83 100644 --- a/entry.go +++ b/entry.go @@ -73,6 +73,9 @@ type Override struct { UsePkgName UsePkgName `json:"usePkgName" toml:"use_pkg_name" xml:"use-pkg-name" yaml:"usePkgName"` // By default all typescript interfaces are exported. Set NoExport to true to prevent that. NoExport bool `json:"noExport" toml:"no_export" xml:"no-export" yaml:"noExport"` + // Setting NullSlicePointers to true causes the builder to add | null to slices of pointers. + // If your pointer slices are nullable, set this to true. + NullSlicePointers bool `json:"nullSlicePointers" toml:"null_slice_pointers" xml:"null-slice-pointers" yaml:"nullSlicePointers"` } // Namer is an interface that allows external interface naming. From 14beb116193e8b080f0114ff6a0c6f969c842647 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Mon, 26 May 2025 15:25:45 -0700 Subject: [PATCH 2/3] fix test --- printer_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/printer_test.go b/printer_test.go index 7488033..93afd41 100644 --- a/printer_test.go +++ b/printer_test.go @@ -112,6 +112,7 @@ func ExampleGoty_Print() { // keepUnderscores: boolean; // usePkgName: number; // noExport: boolean; + // nullSlicePointers: boolean; // }; // // // Packages parsed: From e143ab358bbedc333a2992177c592987e41dceb0 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Mon, 26 May 2025 15:27:03 -0700 Subject: [PATCH 3/3] ignore a long line --- entry.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entry.go b/entry.go index e4fcf83..0f7784c 100644 --- a/entry.go +++ b/entry.go @@ -46,6 +46,8 @@ type Config struct { type Overrides map[any]Override // Override is a struct that contains overrides for either a specific type or for all types (when global). +// +//nolint:lll // Can't break this up I don't think. type Override struct { // Namer is a function that can be used to customize the typescript interface name. // Use this to add a prefix, suffix or any custom name changes you wish.