Skip to content

Commit

Permalink
fix: embedded fields response generation for tools (#1622)
Browse files Browse the repository at this point in the history
  • Loading branch information
RutZap authored Oct 2, 2024
1 parent 09d55a4 commit 40d2187
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 151 deletions.
2 changes: 1 addition & 1 deletion tools/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ func (g *Generator) makeResponsesForModel(model *proto.Model, pathPrefix string,
if f.IsHasMany() {
prefix = prefix + "[*]"
}
embeddedFields, err := g.makeResponsesForModel(g.Schema.FindModel(f.ModelName), prefix, fieldEmbeddings, []string{})
embeddedFields, err := g.makeResponsesForModel(g.Schema.FindModel(f.Type.ModelName.Value), prefix, fieldEmbeddings, []string{})
if err != nil {
return nil, err
}
Expand Down
203 changes: 77 additions & 126 deletions tools/testdata/blog/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -1245,234 +1245,185 @@
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].author.title" },
"fieldLocation": { "path": "$.results[*].author.email" },
"fieldType": "TYPE_STRING",
"displayName": "Title",
"displayName": "Email",
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].author.description" },
"fieldType": "TYPE_STRING",
"displayName": "Description",
"fieldLocation": { "path": "$.results[*].author.emailVerified" },
"fieldType": "TYPE_BOOL",
"displayName": "Email verified",
"displayOrder": 1,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].author.content" },
"fieldType": "TYPE_MARKDOWN",
"displayName": "Content",
"fieldLocation": { "path": "$.results[*].author.password" },
"fieldType": "TYPE_PASSWORD",
"displayName": "Password",
"displayOrder": 2,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].author.published" },
"fieldType": "TYPE_BOOL",
"displayName": "Published",
"fieldLocation": { "path": "$.results[*].author.externalId" },
"fieldType": "TYPE_STRING",
"displayName": "External id",
"displayOrder": 3,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].author.authorId" },
"fieldType": "TYPE_ID",
"displayName": "Author",
"fieldLocation": { "path": "$.results[*].author.issuer" },
"fieldType": "TYPE_STRING",
"displayName": "Issuer",
"displayOrder": 4,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].author.image" },
"fieldType": "TYPE_FILE",
"displayName": "Image",
"fieldLocation": { "path": "$.results[*].author.name" },
"fieldType": "TYPE_STRING",
"displayName": "Name",
"displayOrder": 5,
"visible": true,
"imagePreview": true
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].author.tags" },
"fieldLocation": { "path": "$.results[*].author.givenName" },
"fieldType": "TYPE_STRING",
"repeated": true,
"displayName": "Tags",
"displayName": "Given name",
"displayOrder": 6,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].author.categoryId" },
"fieldType": "TYPE_ID",
"displayName": "Category",
"fieldLocation": { "path": "$.results[*].author.familyName" },
"fieldType": "TYPE_STRING",
"displayName": "Family name",
"displayOrder": 7,
"visible": true,
"link": {
"toolId": "getCategory",
"data": [
{
"key": "$.id",
"path": { "path": "$.results[*].author.categoryId" }
}
]
}
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].author.comments" },
"fieldType": "TYPE_MODEL",
"repeated": true,
"displayName": "Comments",
"fieldLocation": { "path": "$.results[*].author.middleName" },
"fieldType": "TYPE_STRING",
"displayName": "Middle name",
"displayOrder": 8,
"visible": true,
"link": {
"toolId": "listComments",
"data": [
{
"key": "$.where.parent.id.equals",
"path": { "path": "$.results[*].id" }
}
]
}
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].author.id" },
"fieldType": "TYPE_ID",
"displayName": "Id",
"displayOrder": 12,
"fieldLocation": { "path": "$.results[*].author.nickName" },
"fieldType": "TYPE_STRING",
"displayName": "Nick name",
"displayOrder": 9,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].author.createdAt" },
"fieldType": "TYPE_DATETIME",
"displayName": "Created at",
"displayOrder": 13,
"fieldLocation": { "path": "$.results[*].author.profile" },
"fieldType": "TYPE_STRING",
"displayName": "Profile",
"displayOrder": 10,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].author.updatedAt" },
"fieldType": "TYPE_DATETIME",
"displayName": "Updated at",
"displayOrder": 14,
"fieldLocation": { "path": "$.results[*].author.picture" },
"fieldType": "TYPE_STRING",
"displayName": "Picture",
"displayOrder": 11,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].authorId" },
"fieldType": "TYPE_ID",
"displayName": "Author",
"displayOrder": 4,
"fieldLocation": { "path": "$.results[*].author.website" },
"fieldType": "TYPE_STRING",
"displayName": "Website",
"displayOrder": 12,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].image" },
"fieldType": "TYPE_FILE",
"displayName": "Image",
"displayOrder": 5,
"visible": true,
"imagePreview": true
"fieldLocation": { "path": "$.results[*].author.gender" },
"fieldType": "TYPE_STRING",
"displayName": "Gender",
"displayOrder": 13,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].tags" },
"fieldLocation": { "path": "$.results[*].author.zoneInfo" },
"fieldType": "TYPE_STRING",
"repeated": true,
"displayName": "Tags",
"displayOrder": 6,
"displayName": "Zone info",
"displayOrder": 14,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].category.title" },
"fieldLocation": { "path": "$.results[*].author.locale" },
"fieldType": "TYPE_STRING",
"displayName": "Title",
"displayName": "Locale",
"displayOrder": 15,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].category.description" },
"fieldType": "TYPE_STRING",
"displayName": "Description",
"displayOrder": 1,
"fieldLocation": { "path": "$.results[*].author.id" },
"fieldType": "TYPE_ID",
"displayName": "Id",
"displayOrder": 17,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].category.content" },
"fieldType": "TYPE_MARKDOWN",
"displayName": "Content",
"displayOrder": 2,
"fieldLocation": { "path": "$.results[*].author.createdAt" },
"fieldType": "TYPE_DATETIME",
"displayName": "Created at",
"displayOrder": 18,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].category.published" },
"fieldType": "TYPE_BOOL",
"displayName": "Published",
"displayOrder": 3,
"fieldLocation": { "path": "$.results[*].author.updatedAt" },
"fieldType": "TYPE_DATETIME",
"displayName": "Updated at",
"displayOrder": 19,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].category.authorId" },
"fieldLocation": { "path": "$.results[*].authorId" },
"fieldType": "TYPE_ID",
"displayName": "Author",
"displayOrder": 4,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].category.image" },
"fieldLocation": { "path": "$.results[*].image" },
"fieldType": "TYPE_FILE",
"displayName": "Image",
"displayOrder": 5,
"visible": true,
"imagePreview": true
},
{
"fieldLocation": { "path": "$.results[*].category.tags" },
"fieldLocation": { "path": "$.results[*].tags" },
"fieldType": "TYPE_STRING",
"repeated": true,
"displayName": "Tags",
"displayOrder": 6,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].category.categoryId" },
"fieldType": "TYPE_ID",
"displayName": "Category",
"displayOrder": 7,
"visible": true,
"link": {
"toolId": "getCategory",
"data": [
{
"key": "$.id",
"path": { "path": "$.results[*].category.categoryId" }
}
]
}
},
{
"fieldLocation": { "path": "$.results[*].category.comments" },
"fieldType": "TYPE_MODEL",
"repeated": true,
"displayName": "Comments",
"displayOrder": 8,
"visible": true,
"link": {
"toolId": "listComments",
"data": [
{
"key": "$.where.parent.id.equals",
"path": { "path": "$.results[*].id" }
}
]
}
"fieldLocation": { "path": "$.results[*].category.name" },
"fieldType": "TYPE_STRING",
"displayName": "Name",
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].category.id" },
"fieldType": "TYPE_ID",
"displayName": "Id",
"displayOrder": 12,
"displayOrder": 2,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].category.createdAt" },
"fieldType": "TYPE_DATETIME",
"displayName": "Created at",
"displayOrder": 13,
"displayOrder": 3,
"visible": true
},
{
"fieldLocation": { "path": "$.results[*].category.updatedAt" },
"fieldType": "TYPE_DATETIME",
"displayName": "Updated at",
"displayOrder": 14,
"displayOrder": 4,
"visible": true
},
{
Expand Down
26 changes: 3 additions & 23 deletions tools/testdata/input_get_entry_actions/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,45 +201,25 @@
"displayOrder": 1,
"visible": true
},
{
"fieldLocation": { "path": "$.supplier.name" },
"fieldType": "TYPE_STRING",
"displayName": "Name",
"visible": true
},
{
"fieldLocation": { "path": "$.supplier.sku" },
"fieldType": "TYPE_STRING",
"displayName": "Sku",
"displayOrder": 1,
"visible": true
},
{
"fieldLocation": { "path": "$.supplier.supplierId" },
"fieldType": "TYPE_ID",
"displayName": "Supplier",
"displayOrder": 2,
"visible": true
},
{
"fieldLocation": { "path": "$.supplier.id" },
"fieldType": "TYPE_ID",
"displayName": "Id",
"displayOrder": 5,
"displayOrder": 1,
"visible": true
},
{
"fieldLocation": { "path": "$.supplier.createdAt" },
"fieldType": "TYPE_DATETIME",
"displayName": "Created at",
"displayOrder": 6,
"displayOrder": 2,
"visible": true
},
{
"fieldLocation": { "path": "$.supplier.updatedAt" },
"fieldType": "TYPE_DATETIME",
"displayName": "Updated at",
"displayOrder": 7,
"displayOrder": 3,
"visible": true
},
{
Expand Down
2 changes: 1 addition & 1 deletion tools/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestGenerateTools(t *testing.T) {
return
}

fmt.Println(string(actual))
fmt.Println(testCase.Name(), string(actual))

assert.Fail(t, "actual tools JSON does not match expected", explanation)
})
Expand Down

0 comments on commit 40d2187

Please sign in to comment.