Handle LemmyTime fields

This commit is contained in:
Elara 2023-09-24 19:36:37 -07:00
parent 44dbe8c934
commit 4bc9ac9276
2 changed files with 1451 additions and 1443 deletions

View File

@ -52,7 +52,7 @@ func (s *StructGenerator) Generate(items []extractor.Struct) error {
} }
func getType(f extractor.Field) string { func getType(f extractor.Field) string {
t := transformType(f.Type) t := transformType(f.Name, f.Type)
if f.IsArray { if f.IsArray {
t = "[]" + t t = "[]" + t
} }
@ -62,14 +62,21 @@ func getType(f extractor.Field) string {
return t return t
} }
func transformType(s string) string { func transformType(name, t string) string {
switch s { // Some time fields are strings in the JS client,
// use LemmyTime for those
switch name {
case "published", "updated":
return "LemmyTime"
}
switch t {
case "number": case "number":
return "float64" return "float64"
case "boolean": case "boolean":
return "bool" return "bool"
default: default:
return s return t
} }
} }
@ -81,6 +88,7 @@ func transformFieldName(s string) string {
"Nsfw", "NSFW", "Nsfw", "NSFW",
"Jwt", "JWT", "Jwt", "JWT",
"Crud", "CRUD", "Crud", "CRUD",
"Pm", "PM",
).Replace(s) ).Replace(s)
return s return s
} }

File diff suppressed because it is too large Load Diff