@@ -115,10 +115,10 @@ func (g *Generator) genMethodDefinition() {
115115 g .w ("\n // ----- API Definition -------------------------------------------------------\n \n " )
116116
117117 if g .Endpoint .Type == "xpack" {
118- g .w (`// ` + g .Endpoint .MethodWithNamespace () + " - " + g .Endpoint .Documentation )
118+ g .w (`// ` + g .Endpoint .MethodWithNamespace () + " - " + g .Endpoint .Documentation . Description )
119119 } else {
120- if g .Endpoint .Description != "" {
121- words := strings .Split (g .Endpoint .Description , " " )
120+ if g .Endpoint .Documentation . Description != "" {
121+ words := strings .Split (g .Endpoint .Documentation . Description , " " )
122122 initial := strings .ToLower (words [0 :1 ][0 ])
123123 description := initial + " " + strings .Join (words [1 :], " " )
124124 lines := strings .Split (description , "\n " )
@@ -127,12 +127,11 @@ func (g *Generator) genMethodDefinition() {
127127 for _ , line := range lines [1 :] {
128128 g .w ("\n // " + line )
129129 }
130- g .w ("\n " )
131130 }
131+ }
132132
133- if g .Endpoint .Documentation != "" {
134- g .w ("//\n " + `// See full documentation at ` + g .Endpoint .Documentation + "." )
135- }
133+ if g .Endpoint .Documentation .URL != "" {
134+ g .w ("\n //\n " + `// See full documentation at ` + g .Endpoint .Documentation .URL + "." )
136135 }
137136
138137 g .w (`
@@ -174,26 +173,26 @@ func (g *Generator) genRequestStruct() {
174173type ` + g .Endpoint .MethodWithNamespace () + `Request struct {` )
175174 specialFields := []string {"index" , "type" , "id" }
176175 for _ , n := range specialFields {
177- if param , ok := g .Endpoint .URL .Parts [n ]; ok {
176+ if param , ok := g .Endpoint .URL .AllParts [n ]; ok {
178177 g .w ("\n \t " + param .GoName ())
179178 g .w ("\t " + param .GoType (true ))
180179 }
181180 }
182181
183- if len (g .Endpoint .URL .Parts ) > 0 {
182+ if len (g .Endpoint .URL .AllParts ) > 0 {
184183 g .w ("\n " )
185184 }
186185
187186 if g .Endpoint .Body != nil {
188187 g .w ("\n \t Body io.Reader" )
189188 }
190189
191- if len (g .Endpoint .URL .Parts ) > 0 || g .Endpoint .Body != nil {
190+ if len (g .Endpoint .URL .AllParts ) > 0 || g .Endpoint .Body != nil {
192191 g .w ("\n " )
193192 }
194193
195194 for _ , name := range g .Endpoint .URL .PartNamesSorted {
196- p , ok := g .Endpoint .URL .Parts [name ]
195+ p , ok := g .Endpoint .URL .AllParts [name ]
197196 if ! ok {
198197 panic (fmt .Sprintf ("Part %q not found" , name ))
199198 }
@@ -212,7 +211,7 @@ type ` + g.Endpoint.MethodWithNamespace() + `Request struct {`)
212211
213212 }
214213
215- if len (g .Endpoint .URL .Parts ) > 0 {
214+ if len (g .Endpoint .URL .AllParts ) > 0 {
216215 g .w ("\n " )
217216 }
218217
@@ -222,7 +221,7 @@ type ` + g.Endpoint.MethodWithNamespace() + `Request struct {`)
222221 panic (fmt .Sprintf ("Parameter %q not found" , name ))
223222 }
224223
225- if _ , ok := g .Endpoint .URL .Parts [name ]; ok {
224+ if _ , ok := g .Endpoint .URL .AllParts [name ]; ok {
226225 continue // skip params which are also parts
227226 }
228227
@@ -348,7 +347,7 @@ func (f ` + g.Endpoint.MethodWithNamespace() + `) WithBody(v io.Reader) func(*`
348347
349348 // Generate With... methods for parts
350349 for _ , pName := range g .Endpoint .URL .PartNamesSorted {
351- if p , ok := g .Endpoint .URL .Parts [pName ]; ok {
350+ if p , ok := g .Endpoint .URL .AllParts [pName ]; ok {
352351 if skipRequiredArgs [p .Name ] && p .Name != "type" {
353352 continue
354353 }
@@ -361,7 +360,7 @@ func (f ` + g.Endpoint.MethodWithNamespace() + `) WithBody(v io.Reader) func(*`
361360
362361 // Generate With... methods for params
363362 for _ , pName := range g .Endpoint .URL .ParamNamesSorted {
364- if _ , ok := g .Endpoint .URL .Parts [pName ]; ok {
363+ if _ , ok := g .Endpoint .URL .AllParts [pName ]; ok {
365364 continue // skip params which are also parts
366365 }
367366 if p , ok := g .Endpoint .URL .Params [pName ]; ok {
@@ -452,15 +451,15 @@ func (r ` + g.Endpoint.MethodWithNamespace() + `Request) Do(ctx context.Context,
452451 }` )
453452 g .w ("\n \n " )
454453 default :
455- g .w ("\t " + `method = "` + g .Endpoint .Methods [0 ] + `"` + "\n \n " )
454+ g .w ("\t " + `method = "` + g .Endpoint .URL . Paths [ 0 ]. Methods [0 ] + `"` + "\n \n " )
456455 }
457456
458457 // Get default part values for specific APIs
459458 // TODO: Move to overrides
460459 var defparts bool
461460 switch g .Endpoint .Name {
462461 case "index" , "create" , "delete" , "explain" , "exists" , "get" , "get_source" , "update" , "termvectors" :
463- for _ , p := range g .Endpoint .URL .Parts {
462+ for _ , p := range g .Endpoint .URL .AllParts {
464463 if p .Default != nil {
465464 var fieldName string
466465 var fieldValue string
@@ -504,25 +503,25 @@ func (r ` + g.Endpoint.MethodWithNamespace() + `Request) Do(ctx context.Context,
504503
505504 pathGrow .WriteString (` path.Grow(` )
506505
507- if len (g .Endpoint .URL .Parts ) < 1 {
508- if g .Endpoint .URL .Path == "" {
509- panic (fmt .Sprintf ("FAIL: %q: empty endpoint\n " , g .Endpoint .Name ))
506+ // FIXME: Select longest path based on number of template entries, not string length
507+ longestPath := g .Endpoint .URL .Paths [0 ]
508+ for _ , v := range g .Endpoint .URL .Paths {
509+ if len (v .Path ) > len (longestPath .Path ) {
510+ longestPath = v
510511 }
511- pathGrow .WriteString (`len("` + g .Endpoint .URL .Path + `")` )
512- pathContent .WriteString (` path.WriteString("` + g .Endpoint .URL .Path + `")` + "\n " )
512+ }
513513
514- } else {
515- // FIXME: Select longest path based on number of template entries, not string length
516- longestPath := g .Endpoint .URL .Paths [0 ]
517- for _ , v := range g .Endpoint .URL .Paths {
518- if len (v ) > len (longestPath ) {
519- longestPath = v
520- }
514+ if len (longestPath .Parts ) < 1 {
515+ if len (g .Endpoint .URL .Paths ) < 1 {
516+ panic (fmt .Sprintf ("FAIL: %q: empty endpoint\n " , g .Endpoint .Name ))
521517 }
518+ pathGrow .WriteString (`len("` + longestPath .Path + `")` )
519+ pathContent .WriteString (` path.WriteString("` + longestPath .Path + `")` + "\n " )
522520
521+ } else {
523522 pathParts := make ([]string , 0 )
524523 apiArgs := g .Endpoint .RequiredArguments ()
525- for _ , v := range strings .Split (longestPath , "/" ) {
524+ for _ , v := range strings .Split (longestPath . Path , "/" ) {
526525 if v != "" {
527526 pathParts = append (pathParts , v )
528527 }
@@ -555,7 +554,8 @@ func (r ` + g.Endpoint.MethodWithNamespace() + `Request) Do(ctx context.Context,
555554
556555 // Optional arguments
557556 if p == "" {
558- for _ , a := range g .Endpoint .URL .Parts {
557+ for _ , a := range longestPath .Parts {
558+ // fmt.Printf("a: %+v\n", a)
559559 if strings .HasPrefix (v , "{" ) && a .Name == r .Replace (v ) {
560560 p = a .GoName ()
561561
0 commit comments