diff --git a/v2/internal/binding/binding_test/binding_structwithoutfields_test.go b/v2/internal/binding/binding_test/binding_structwithoutfields_test.go new file mode 100644 index 000000000..4b2289b98 --- /dev/null +++ b/v2/internal/binding/binding_test/binding_structwithoutfields_test.go @@ -0,0 +1,34 @@ +package binding_test + +type WithoutFields struct { +} + +func (s WithoutFields) Get() WithoutFields { + return s +} + +var WithoutFieldsTest = BindingTest{ + name: "StructWithoutFields", + structs: []interface{}{ + &WithoutFields{}, + }, + exemptions: nil, + shouldError: false, + want: ` +export namespace binding_test { + + export class WithoutFields { + + + static createFrom(source: any = {}) { + return new WithoutFields(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + + } + } + +}`, +} diff --git a/v2/internal/binding/binding_test/binding_test.go b/v2/internal/binding/binding_test/binding_test.go index 947c3b08a..a16dde5ea 100644 --- a/v2/internal/binding/binding_test/binding_test.go +++ b/v2/internal/binding/binding_test/binding_test.go @@ -47,8 +47,9 @@ func TestBindings_GenerateModels(t *testing.T) { AnonymousSubStructTest, AnonymousSubStructMultiLevelTest, GeneratedJsEntityWithNestedStructTest, - EntityWithDiffNamespaces, + EntityWithDiffNamespacesTest, SpecialCharacterFieldTest, + WithoutFieldsTest, } testLogger := &logger.Logger{} diff --git a/v2/internal/binding/binding_test/binding_tsgeneration_test.go b/v2/internal/binding/binding_test/binding_tsgeneration_test.go index 06bcae97d..850bc778a 100644 --- a/v2/internal/binding/binding_test/binding_tsgeneration_test.go +++ b/v2/internal/binding/binding_test/binding_tsgeneration_test.go @@ -140,7 +140,7 @@ type ChildPackageEntity struct { ImportedPackage binding_test_import.AWrapper `json:"importedPackage"` } -var EntityWithDiffNamespaces = BindingTest{ +var EntityWithDiffNamespacesTest = BindingTest{ name: "EntityWithDiffNamespaces ", structs: []interface{}{ &ParentPackageEntity{}, diff --git a/v2/internal/typescriptify/typescriptify.go b/v2/internal/typescriptify/typescriptify.go index 3d7256038..85fea9c42 100644 --- a/v2/internal/typescriptify/typescriptify.go +++ b/v2/internal/typescriptify/typescriptify.go @@ -586,9 +586,6 @@ func (t *TypeScriptify) convertType(depth int, typeOf reflect.Type, customCode m return "", nil } fields := t.deepFields(typeOf) - if len(fields) == 0 { - return "", nil - } t.logf(depth, "Converting type %s", typeOf.String()) if differentNamespaces(t.Namespace, typeOf) { return "", nil diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 58a63d837..e4b3eda5c 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added support for proxying assets requests to an external server. Added by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/3463) +- Added support generating bindings for structs without fields. Added by [gjergj](https://github.com/Gjergj) in [PR](https://github.com/wailsapp/wails/pull/3489) ### Fixed - Fixed an issue with missing icon for Windows. Fixed by [@APshenkin](https://github.com/wailsapp/wails/pull/3400)