11package model
22
33import (
4+ "encoding/json"
5+ "log"
46 "regexp"
57 "strings"
68
@@ -21,15 +23,37 @@ func (p *Transformer) mapIntoApiRoutes(resources []*api.Resource) (resp []APIRou
2123 Method : method .Method ,
2224 Description : method .Title ,
2325 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 , "" )) ,
2527 ResponseCode : method .Transactions [0 ].Response .StatusCode ,
2628 JsonSchema : method .Transactions [0 ].Request .Schema .Body ,
2729 })
2830 }
2931 }
3032 return
3133}
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+ }
3357func (p * Transformer ) groupIntoAPIHandler (routes []APIRoute ) map [string ]APIHandler {
3458 handler := make (map [string ]APIHandler )
3559 for _ , route := range routes {
0 commit comments