wails
wails copied to clipboard
`models.ts` is not generated.
Description
When I run wails dev
, I expect frontend/wailsjs/go/models.ts
to be generated, but it is not.
I use wails version v2.0.0-beta.35
.
To Reproduce
- Execute
wails init -t svelte-ts -d foo -n bar
. - Execute
cd foo
. - Add the following to
app.go
.
type Foo struct{}
func (a *App) Foo() *Foo {
return &Foo{}
}
- Execute
wails dev
. - I look for
frontend/wailsjs/go/models.ts
but can't find it.
Expected behaviour
frontend/wailsjs/go/models.ts
is generated.
Screenshots
No response
Attempted Fixes
In wails version v2.0.0-beta.34
frontend/wailsjs/go/models.ts
is generated.
System Details
Wails CLI v2.0.0-beta.35
Scanning system - Please wait (this may take a long time)...Done.
System
------
OS: Windows 10 Home
Version: 2009 (Build: 19044)
ID: 21H2
Go Version: go1.18.1
Platform: windows
Architecture: amd64
Wails
------
Version: v2.0.0-beta.35
Dependency Package Name Status Version
---------- ------------ ------ -------
WebView2 N/A Installed 100.0.1185.50
npm N/A Installed 8.5.5
*upx N/A Installed upx 3.96
*nsis N/A Available
* - Optional Dependency
Diagnosis
---------
Your system is ready for Wails development!
Optional package(s) installation details:
- nsis : Available at https://nsis.sourceforge.io/Download
Additional context
No response
Hi, does your struct have json tags? Wails will only create the models.ts if your go struct has associated json:"" tags and if it exported like:
type MyStruct struct {
ID string `json:"id"`
}
I overlooked that a json tag is required. My apologies.
@mondy is there something we could do in the docs to make this clearer?
@leaanthony
I think changes in the beta version are common. So I don't think it is necessary to mention them in the documentation.
Instead, how about a template where models.ts
is generated by default?
You can use a simplified version of the main.go
code listed here.
I forgot to mention an issue that should have been mentioned.
The following code App.d.ts
is generated by following the steps shown in the introduction.
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {main} from '../models';
export function Foo():Promise<main.Foo>;
export function Greet(arg1:string):Promise<string>;
../models
is imported, but it does not exist. It is incomplete as source code. There is a issue with this condition.
I would like you to generate an empty Foo class
as follows.
export namespace main {
export class Foo {
id: string;
static createFrom(source: any = {}) {
return new Foo(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
}
}
}
Or , if it generates incomplete code, it should output a warning to the CLI when it runs wails dev
at minimum.
I'm wondering if it's more desirable to leave it so it doesn't compile, as that will tell you that you've got something wrong in your code. Or...we could generate a blank model with a comment that warns about this and has a link to the docs.... that actually sounds reasonable to me.
@leaanthony On version v2.0.0-beta.44.2 we cant generate models ((((( You know how fix?
@Osbornnnnn please open a bug with details
I forgot to mention an issue that should have been mentioned. The following code
App.d.ts
is generated by following the steps shown in the introduction.// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT import {main} from '../models'; export function Foo():Promise<main.Foo>; export function Greet(arg1:string):Promise<string>;
../models
is imported, but it does not exist. It is incomplete as source code. There is a issue with this condition. I would like you to generate an emptyFoo class
as follows.export namespace main { export class Foo { id: string; static createFrom(source: any = {}) { return new Foo(source); } constructor(source: any = {}) { if ('string' === typeof source) source = JSON.parse(source); } } }
Or , if it generates incomplete code, it should output a warning to the CLI when it runs
wails dev
at minimum.
~So @leaanthony and @mondy - is this expected behaviour? I was following the getting started guide and ran into the same issue where App.d.ts
was showing an import for models
but models.ts
was nowhere to be found. This was on v2.0.0-rc.1.1
.~
Sorry for the noise, it was a snafu on my end. model.ts
is indeed generated.
@mondy is there something we could do in the docs to make this clearer?
@leaanthony Go has a default transformation of field names between JSON and Go, would it make sense to not require the json:"..."
tag at all?
I'd prefer this approach for sure but remember it did not working correctly for some reason back in the day. If you are happy to look at it, please open a ticket and we can stick it on the board 👍
I only become aware of Wails recently thanks to the Golang Weekly newsletter. Got a little personal project it's perfect for and I've started on. Once I have a bit more familiarity, and if somebody hasn't started on it already, I'll happily take that on.
Any news on this @endophage ? Might have a go this weekend
Bumping this to v2.2
The static analysis approach of v3 will enable us to generate models for unbound structs. Bumping this to v3 as there's been no appetite for this.
I cannot understand what is the reason to have to type json:"name"
against every field in my structs. This is useless. They represent exactly what supposted to be sent/received, however some of them might require extra customization like custom type declaration. They are simply api specification.
My modules (*models) are pure DTOs and they have no any extra properties which must be ignored.
@leaanthony I'd prefer this approach for sure but remember it did not working correctly for some reason back in the day.
Would be nice to get rid of required tags.
Sure thing. Feel free to open a PR to do this 👍