@@ -115,10 +115,10 @@ func (g *Generator) genMethodDefinition() {
115
115
g .w ("\n // ----- API Definition -------------------------------------------------------\n \n " )
116
116
117
117
if g .Endpoint .Type == "xpack" {
118
- g .w (`// ` + g .Endpoint .MethodWithNamespace () + " - " + g .Endpoint .Documentation )
118
+ g .w (`// ` + g .Endpoint .MethodWithNamespace () + " - " + g .Endpoint .Documentation . Description )
119
119
} 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 , " " )
122
122
initial := strings .ToLower (words [0 :1 ][0 ])
123
123
description := initial + " " + strings .Join (words [1 :], " " )
124
124
lines := strings .Split (description , "\n " )
@@ -127,12 +127,11 @@ func (g *Generator) genMethodDefinition() {
127
127
for _ , line := range lines [1 :] {
128
128
g .w ("\n // " + line )
129
129
}
130
- g .w ("\n " )
131
130
}
131
+ }
132
132
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 + "." )
136
135
}
137
136
138
137
g .w (`
@@ -174,26 +173,26 @@ func (g *Generator) genRequestStruct() {
174
173
type ` + g .Endpoint .MethodWithNamespace () + `Request struct {` )
175
174
specialFields := []string {"index" , "type" , "id" }
176
175
for _ , n := range specialFields {
177
- if param , ok := g .Endpoint .URL .Parts [n ]; ok {
176
+ if param , ok := g .Endpoint .URL .AllParts [n ]; ok {
178
177
g .w ("\n \t " + param .GoName ())
179
178
g .w ("\t " + param .GoType (true ))
180
179
}
181
180
}
182
181
183
- if len (g .Endpoint .URL .Parts ) > 0 {
182
+ if len (g .Endpoint .URL .AllParts ) > 0 {
184
183
g .w ("\n " )
185
184
}
186
185
187
186
if g .Endpoint .Body != nil {
188
187
g .w ("\n \t Body io.Reader" )
189
188
}
190
189
191
- if len (g .Endpoint .URL .Parts ) > 0 || g .Endpoint .Body != nil {
190
+ if len (g .Endpoint .URL .AllParts ) > 0 || g .Endpoint .Body != nil {
192
191
g .w ("\n " )
193
192
}
194
193
195
194
for _ , name := range g .Endpoint .URL .PartNamesSorted {
196
- p , ok := g .Endpoint .URL .Parts [name ]
195
+ p , ok := g .Endpoint .URL .AllParts [name ]
197
196
if ! ok {
198
197
panic (fmt .Sprintf ("Part %q not found" , name ))
199
198
}
@@ -212,7 +211,7 @@ type ` + g.Endpoint.MethodWithNamespace() + `Request struct {`)
212
211
213
212
}
214
213
215
- if len (g .Endpoint .URL .Parts ) > 0 {
214
+ if len (g .Endpoint .URL .AllParts ) > 0 {
216
215
g .w ("\n " )
217
216
}
218
217
@@ -222,7 +221,7 @@ type ` + g.Endpoint.MethodWithNamespace() + `Request struct {`)
222
221
panic (fmt .Sprintf ("Parameter %q not found" , name ))
223
222
}
224
223
225
- if _ , ok := g .Endpoint .URL .Parts [name ]; ok {
224
+ if _ , ok := g .Endpoint .URL .AllParts [name ]; ok {
226
225
continue // skip params which are also parts
227
226
}
228
227
@@ -348,7 +347,7 @@ func (f ` + g.Endpoint.MethodWithNamespace() + `) WithBody(v io.Reader) func(*`
348
347
349
348
// Generate With... methods for parts
350
349
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 {
352
351
if skipRequiredArgs [p .Name ] && p .Name != "type" {
353
352
continue
354
353
}
@@ -361,7 +360,7 @@ func (f ` + g.Endpoint.MethodWithNamespace() + `) WithBody(v io.Reader) func(*`
361
360
362
361
// Generate With... methods for params
363
362
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 {
365
364
continue // skip params which are also parts
366
365
}
367
366
if p , ok := g .Endpoint .URL .Params [pName ]; ok {
@@ -452,15 +451,15 @@ func (r ` + g.Endpoint.MethodWithNamespace() + `Request) Do(ctx context.Context,
452
451
}` )
453
452
g .w ("\n \n " )
454
453
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 " )
456
455
}
457
456
458
457
// Get default part values for specific APIs
459
458
// TODO: Move to overrides
460
459
var defparts bool
461
460
switch g .Endpoint .Name {
462
461
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 {
464
463
if p .Default != nil {
465
464
var fieldName string
466
465
var fieldValue string
@@ -504,25 +503,25 @@ func (r ` + g.Endpoint.MethodWithNamespace() + `Request) Do(ctx context.Context,
504
503
505
504
pathGrow .WriteString (` path.Grow(` )
506
505
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
510
511
}
511
- pathGrow .WriteString (`len("` + g .Endpoint .URL .Path + `")` )
512
- pathContent .WriteString (` path.WriteString("` + g .Endpoint .URL .Path + `")` + "\n " )
512
+ }
513
513
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 ))
521
517
}
518
+ pathGrow .WriteString (`len("` + longestPath .Path + `")` )
519
+ pathContent .WriteString (` path.WriteString("` + longestPath .Path + `")` + "\n " )
522
520
521
+ } else {
523
522
pathParts := make ([]string , 0 )
524
523
apiArgs := g .Endpoint .RequiredArguments ()
525
- for _ , v := range strings .Split (longestPath , "/" ) {
524
+ for _ , v := range strings .Split (longestPath . Path , "/" ) {
526
525
if v != "" {
527
526
pathParts = append (pathParts , v )
528
527
}
@@ -555,7 +554,8 @@ func (r ` + g.Endpoint.MethodWithNamespace() + `Request) Do(ctx context.Context,
555
554
556
555
// Optional arguments
557
556
if p == "" {
558
- for _ , a := range g .Endpoint .URL .Parts {
557
+ for _ , a := range longestPath .Parts {
558
+ // fmt.Printf("a: %+v\n", a)
559
559
if strings .HasPrefix (v , "{" ) && a .Name == r .Replace (v ) {
560
560
p = a .GoName ()
561
561
0 commit comments