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..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. @@ -73,6 +75,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. 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: