1
1
package model
2
2
3
3
import (
4
+ "encoding/json"
5
+ "log"
4
6
"regexp"
5
7
"strings"
6
8
@@ -21,15 +23,37 @@ func (p *Transformer) mapIntoApiRoutes(resources []*api.Resource) (resp []APIRou
21
23
Method : method .Method ,
22
24
Description : method .Title ,
23
25
Route : re .ReplaceAllString (method .Href .Path , "" ),
24
- Response : method .Transactions [0 ].Response .Body .Body ,
26
+ Response : p . addSampleMetaDataToResponse ( method .Transactions [0 ].Response .Body .Body , method . Method , re . ReplaceAllString ( method . Href . Path , "" )) ,
25
27
ResponseCode : method .Transactions [0 ].Response .StatusCode ,
26
28
JsonSchema : method .Transactions [0 ].Request .Schema .Body ,
27
29
})
28
30
}
29
31
}
30
32
return
31
33
}
32
-
34
+ func (p * Transformer ) addSampleMetaDataToResponse (body string , method string , path string ) string {
35
+ if method == "GET" && strings .Count (path , "/" ) == 1 {
36
+ var result map [string ]interface {}
37
+ json .Unmarshal ([]byte (body ), & result )
38
+ for key , value := range result {
39
+ // Each value is an interface{} type, that is type asserted as a string
40
+ log .Println (key , value )
41
+ }
42
+ samplePagination := make (map [string ]string )
43
+ samplePagination ["page" ] = "1"
44
+ samplePagination ["per_page" ] = "25"
45
+ samplePagination ["previous_page" ] = "1"
46
+ samplePagination ["next_page" ] = "1"
47
+ samplePagination ["last_page" ] = "1"
48
+ samplePagination ["total_entries" ] = "100"
49
+ meta := make (map [string ]map [string ]string )
50
+ meta ["pagination" ] = samplePagination
51
+ result ["meta" ] = meta
52
+ data , _ := json .Marshal (result )
53
+ return string (data )
54
+ }
55
+ return body
56
+ }
33
57
func (p * Transformer ) groupIntoAPIHandler (routes []APIRoute ) map [string ]APIHandler {
34
58
handler := make (map [string ]APIHandler )
35
59
for _ , route := range routes {
0 commit comments