mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 12:12:39 +08:00
parent
de1d032f10
commit
2d4f7f4de8
@ -88,17 +88,25 @@ func (b *Bindings) GenerateModels() ([]byte, error) {
|
||||
models := map[string]string{}
|
||||
var seen slicer.StringSlicer
|
||||
allStructNames := b.getAllStructNames()
|
||||
allStructNames.Sort()
|
||||
for packageName, structsToGenerate := range b.structsToGenerateTS {
|
||||
thisPackageCode := ""
|
||||
w := typescriptify.New()
|
||||
w.Namespace = packageName
|
||||
w.WithBackupDir("")
|
||||
w.KnownStructs = allStructNames
|
||||
for structName, structInterface := range structsToGenerate {
|
||||
// sort the structs
|
||||
var structNames []string
|
||||
for structName := range structsToGenerate {
|
||||
structNames = append(structNames, structName)
|
||||
}
|
||||
sort.Strings(structNames)
|
||||
for _, structName := range structNames {
|
||||
fqstructname := packageName + "." + structName
|
||||
if seen.Contains(fqstructname) {
|
||||
continue
|
||||
}
|
||||
structInterface := structsToGenerate[structName]
|
||||
w.Add(structInterface)
|
||||
}
|
||||
str, err := w.Convert(nil)
|
||||
|
@ -0,0 +1,88 @@
|
||||
package binding_test
|
||||
|
||||
type Multistruct1 struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (s Multistruct1) Get() Multistruct1 {
|
||||
return s
|
||||
}
|
||||
|
||||
type Multistruct2 struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (s Multistruct2) Get() Multistruct2 {
|
||||
return s
|
||||
}
|
||||
|
||||
type Multistruct3 struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (s Multistruct3) Get() Multistruct3 {
|
||||
return s
|
||||
}
|
||||
|
||||
type Multistruct4 struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (s Multistruct4) Get() Multistruct4 {
|
||||
return s
|
||||
}
|
||||
|
||||
var MultistructTest = BindingTest{
|
||||
name: "Multistruct",
|
||||
structs: []interface{}{
|
||||
&Multistruct1{},
|
||||
&Multistruct2{},
|
||||
&Multistruct3{},
|
||||
&Multistruct4{},
|
||||
},
|
||||
exemptions: nil,
|
||||
shouldError: false,
|
||||
want: `export namespace binding_test {
|
||||
export class Multistruct1 {
|
||||
name: string;
|
||||
static createFrom(source: any = {}) {
|
||||
return new Multistruct1(source);
|
||||
}
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.name = source["name"];
|
||||
}
|
||||
}
|
||||
export class Multistruct2 {
|
||||
name: string;
|
||||
static createFrom(source: any = {}) {
|
||||
return new Multistruct2(source);
|
||||
}
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.name = source["name"];
|
||||
}
|
||||
}
|
||||
export class Multistruct3 {
|
||||
name: string;
|
||||
static createFrom(source: any = {}) {
|
||||
return new Multistruct3(source);
|
||||
}
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.name = source["name"];
|
||||
}
|
||||
}
|
||||
export class Multistruct4 {
|
||||
name: string;
|
||||
static createFrom(source: any = {}) {
|
||||
return new Multistruct4(source);
|
||||
}
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.name = source["name"];
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
}
|
@ -28,6 +28,7 @@ func TestBindings_GenerateModels(t *testing.T) {
|
||||
NestedFieldTest,
|
||||
NonStringMapKeyTest,
|
||||
SingleFieldTest,
|
||||
MultistructTest,
|
||||
}
|
||||
|
||||
testLogger := &logger.Logger{}
|
||||
|
Loading…
Reference in New Issue
Block a user