Fix ExportSettings endpoint

This commit is contained in:
Elara 2023-12-15 09:25:29 -08:00
parent 993d64b9d1
commit 27fc1cd810
4 changed files with 1271 additions and 1241 deletions

View File

@ -77,6 +77,11 @@ func (e *Extractor) Extract() ([]Route, []Struct) {
returnID := signature.Get("type.typeArguments.0.target").Int()
returnName := signature.Get("type.typeArguments.0.name").String()
anyType := false
if returnName == "any" {
anyType = true
}
// Get the referenced structs from the JSON document
e.getStructs([]int64{paramsID, returnID}, structs)
@ -102,6 +107,10 @@ func (e *Extractor) Extract() ([]Route, []Struct) {
returnName = ""
}
if anyType {
returnName = "map[string]any"
}
out = append(out, Route{
Name: name,
Summary: summary,

View File

@ -31,9 +31,12 @@ func (r *RoutesGenerator) Generate(routes []extractor.Route) error {
g.Id("data").Id(r.ParamsName)
}
}).ParamsFunc(func(g *jen.Group) {
if r.ReturnName != "" {
if r.ReturnName == "map[string]any" {
g.Map(jen.String()).Any()
} else if r.ReturnName != "" {
g.Op("*").Id(r.ReturnName)
}
g.Error()
}).BlockFunc(func(g *jen.Group) {
data := jen.Id("data")
@ -47,16 +50,29 @@ func (r *RoutesGenerator) Generate(routes []extractor.Route) error {
returnName = "emptyResponse"
}
g.Id("resData").Op(":=").Op("&").Id(returnName).Block()
if returnName == "map[string]any" {
g.Id("resData").Op(":=").Map(jen.String()).Any().Block()
} else {
g.Id("resData").Op(":=").Op("&").Id(returnName).Block()
}
funcName := "req"
if r.Method == "GET" {
funcName = "getReq"
}
g.List(jen.Id("res"), jen.Err()).Op(":=").Id("c").Dot(funcName).Params(
jen.Id("ctx"), jen.Lit(r.Method), jen.Lit(r.Path), data, jen.Id("resData"),
)
g.List(jen.Id("res"), jen.Err()).Op(":=").Id("c").Dot(funcName).ParamsFunc(func(g *jen.Group) {
g.Id("ctx")
g.Lit(r.Method)
g.Lit(r.Path)
g.Add(data)
if returnName == "map[string]any" {
g.Op("&").Id("resData")
} else {
g.Id("resData")
}
})
g.If(jen.Err().Op("!=").Nil()).BlockFunc(func(g *jen.Group) {
if returnName == "emptyResponse" {
g.Return(jen.Err())
@ -65,7 +81,12 @@ func (r *RoutesGenerator) Generate(routes []extractor.Route) error {
}
})
g.Err().Op("=").Id("resError").Params(jen.Id("res"), jen.Id("resData").Dot("Error"))
if r.ReturnName == "map[string]any" {
g.Err().Op("=").Id("resError").Params(jen.Id("res"), jen.Id("NewOptionalNil[string]").Params())
} else {
g.Err().Op("=").Id("resError").Params(jen.Id("res"), jen.Id("resData").Dot("Error"))
}
g.If(jen.Err().Op("!=").Nil()).BlockFunc(func(g *jen.Group) {
if returnName == "emptyResponse" {
g.Return(jen.Err())

View File

@ -442,17 +442,17 @@ func (c *Client) EditSite(ctx context.Context, data EditSite) (*SiteResponse, er
Export a backup of your user settings, including your saved content,
followed communities, and blocks.
*/
func (c *Client) ExportSettings(ctx context.Context) error {
resData := &emptyResponse{}
res, err := c.getReq(ctx, "GET", "/user/export_settings", nil, resData)
func (c *Client) ExportSettings(ctx context.Context) (map[string]any, error) {
resData := map[string]any{}
res, err := c.getReq(ctx, "GET", "/user/export_settings", nil, &resData)
if err != nil {
return err
return nil, err
}
err = resError(res, resData.Error)
err = resError(res, NewOptionalNil[string]())
if err != nil {
return err
return nil, err
}
return nil
return resData, nil
}
// A moderator can feature a community post ( IE stick it to the top of a community ).

File diff suppressed because it is too large Load Diff