Skip to content

Commit

Permalink
chore: add wrapper response entries for results and pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
RutZap committed Sep 13, 2024
1 parent 9ad728d commit e1d1792
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tools/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ func (g *Generator) generateResponses() error {
if tool.Action.IsList() {
pathPrefix = ".results[*]"
tool.Config.Response = append(tool.Config.Response, getPageInfoResponses()...)
// appent wrapper response for the results
tool.Config.Response = append(tool.Config.Response, &toolsproto.ResponseFieldConfig{
FieldLocation: &toolsproto.JsonPath{Path: "$.results"},
FieldType: proto.Type_TYPE_OBJECT,
DisplayName: "Results",
Visible: true,
})
}
fields, err := g.makeResponsesForModel(tool.Model, pathPrefix, tool.Action.GetResponseEmbeds(), tool.SortableFields)
if err != nil {
Expand Down Expand Up @@ -657,6 +664,12 @@ func (g *Generator) makeTitle(action *proto.Action, model *proto.Model) *toolspr
// getPageInfoResponses will return the responses for pageInfo (by default available on all autogenerated LIST actions)
func getPageInfoResponses() []*toolsproto.ResponseFieldConfig {
return []*toolsproto.ResponseFieldConfig{
{
FieldLocation: &toolsproto.JsonPath{Path: "$.pageInfo"},
FieldType: proto.Type_TYPE_OBJECT,
DisplayName: "PageInfo",
Visible: false,
},
{
FieldLocation: &toolsproto.JsonPath{Path: "$.pageInfo.count"},
FieldType: proto.Type_TYPE_INT,
Expand Down
44 changes: 44 additions & 0 deletions tools/testdata/blog/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,11 @@
}
],
"response": [
{
"fieldLocation": { "path": "$.pageInfo" },
"fieldType": "TYPE_OBJECT",
"displayName": "PageInfo"
},
{
"fieldLocation": { "path": "$.pageInfo.count" },
"fieldType": "TYPE_INT",
Expand All @@ -577,6 +582,12 @@
"fieldType": "TYPE_STRING",
"displayName": "End cursor"
},
{
"fieldLocation": { "path": "$.results" },
"fieldType": "TYPE_OBJECT",
"displayName": "Results",
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].name" },
"fieldType": "TYPE_STRING",
Expand Down Expand Up @@ -716,6 +727,11 @@
}
],
"response": [
{
"fieldLocation": { "path": "$.pageInfo" },
"fieldType": "TYPE_OBJECT",
"displayName": "PageInfo"
},
{
"fieldLocation": { "path": "$.pageInfo.count" },
"fieldType": "TYPE_INT",
Expand All @@ -741,6 +757,12 @@
"fieldType": "TYPE_STRING",
"displayName": "End cursor"
},
{
"fieldLocation": { "path": "$.results" },
"fieldType": "TYPE_OBJECT",
"displayName": "Results",
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].content" },
"fieldType": "TYPE_STRING",
Expand Down Expand Up @@ -851,6 +873,11 @@
}
],
"response": [
{
"fieldLocation": { "path": "$.pageInfo" },
"fieldType": "TYPE_OBJECT",
"displayName": "PageInfo"
},
{
"fieldLocation": { "path": "$.pageInfo.count" },
"fieldType": "TYPE_INT",
Expand All @@ -876,6 +903,12 @@
"fieldType": "TYPE_STRING",
"displayName": "End cursor"
},
{
"fieldLocation": { "path": "$.results" },
"fieldType": "TYPE_OBJECT",
"displayName": "Results",
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].title" },
"fieldType": "TYPE_STRING",
Expand Down Expand Up @@ -1038,6 +1071,11 @@
}
],
"response": [
{
"fieldLocation": { "path": "$.pageInfo" },
"fieldType": "TYPE_OBJECT",
"displayName": "PageInfo"
},
{
"fieldLocation": { "path": "$.pageInfo.count" },
"fieldType": "TYPE_INT",
Expand All @@ -1063,6 +1101,12 @@
"fieldType": "TYPE_STRING",
"displayName": "End cursor"
},
{
"fieldLocation": { "path": "$.results" },
"fieldType": "TYPE_OBJECT",
"displayName": "Results",
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].title" },
"fieldType": "TYPE_STRING",
Expand Down

0 comments on commit e1d1792

Please sign in to comment.