Skip to content

Commit

Permalink
fix(gen): fix #76
Browse files Browse the repository at this point in the history
  • Loading branch information
jaronnie committed Sep 16, 2024
1 parent 279a227 commit 3efbe90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .template/client/client-go/typed/resource.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func new{{.Resource | FirstUpper | ToCamel}}Client(c *{{.Scope | FirstUpper | To
Params({{if eq $v.Request.Body "*"}}{{else}}{{range $q := $v.QueryParams}}
restc.QueryParam{Name: "{{$q.Name}}", Value: param.{{$q.GoName}}},{{end}}{{end}}
).
{{ if eq $v.Method "GET" }}{{else}}Body({{if eq $v.Request.Body ""}}nil{{else if eq $v.Request.Body "*"}}param{{else if ne $v.Method "GET"}}param.{{$v.Request.RealBodyName}}{{else}}nil{{end}}).{{end}}
{{ if or (eq $v.Method "GET") (eq $v.Method "DELETE") }}{{else}}Body({{if eq $v.Request.Body ""}}nil{{else if eq $v.Request.Body "*"}}param{{else if or (ne $v.Method "GET") (ne $v.Method "DELETE")}}param.{{$v.Request.RealBodyName}}{{else}}nil{{end}}).{{end}}
Do(ctx).
Into(&resp, {{$.IsWrapHTTPResponse}})

Expand Down
12 changes: 0 additions & 12 deletions internal/gen/gensdk/jparser/api/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ func CreateQueryParams(route *spec.Route) []*vars.QueryParam {
return nil
}

//members := route.RequestType.(spec.DefineStruct).GetTagMembers("form")
//params := make([]*vars.QueryParam, 0)
//for _, member := range members {
// name, _ := member.GetPropertyName()
// param := &vars.QueryParam{
// GoName: stringx.FirstUpper(member.Name),
// Name: name,
// }
// params = append(params, param)
//}
//return params

return extractQueryParams(route.RequestType.(spec.DefineStruct))
}

Expand Down
13 changes: 11 additions & 2 deletions internal/gen/gensdk/jparser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@ func genHTTPInterfaces(config *config.Config, fds []*desc.FileDescriptor, apiSpe
case *annotations.HttpRule_Post:
httpInterface.Method = http.MethodPost
httpInterface.URL = httpRule.Post
case *annotations.HttpRule_Put:
httpInterface.Method = http.MethodPut
httpInterface.URL = httpRule.Put
case *annotations.HttpRule_Delete:
httpInterface.Method = http.MethodDelete
httpInterface.URL = httpRule.Delete
case *annotations.HttpRule_Patch:
httpInterface.Method = http.MethodPatch
httpInterface.URL = httpRule.Patch
}

var requestBodyName string
if (httpInterface.Method == http.MethodPost) && rule.Body != "*" {
if (httpInterface.Method == http.MethodPost || httpInterface.Method == http.MethodPut || httpInterface.Method == http.MethodPatch) && rule.Body != "*" {
for _, v := range method.GetInputType().GetFields() {
if rule.Body == v.GetName() {
requestBodyName = v.GetName()
Expand Down Expand Up @@ -119,7 +128,7 @@ func genHTTPInterfaces(config *config.Config, fds []*desc.FileDescriptor, apiSpe
Type: "api",
FullName: fmt.Sprintf("param %s.%s", "types", stringx.FirstUpper(route.RequestType.Name())),
}
if strings.ToUpper(route.Method) == http.MethodPost {
if strings.ToUpper(route.Method) == http.MethodPost || strings.ToUpper(route.Method) == http.MethodPut || strings.ToUpper(route.Method) == http.MethodPatch {
httpInterface.Request.Body = "*"
}
} else {
Expand Down

0 comments on commit 3efbe90

Please sign in to comment.