Skip to content

Commit 2b89f77

Browse files
committed
fix: Handle relations in table options descriptions
1 parent d20c171 commit 2b89f77

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

docs/table_options.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ import (
1212
invoschema "github.com/invopop/jsonschema"
1313
)
1414

15+
func transformDescription(table *schema.Table, tableNamesToOptionsDocs map[string]string) {
16+
if tableNamesToOptionsDocs[table.Name] != "" {
17+
table.Description = table.Description + "\n\n" + tableNamesToOptionsDocs[table.Name]
18+
}
19+
for _, rel := range table.Relations {
20+
transformDescription(rel, tableNamesToOptionsDocs)
21+
}
22+
}
23+
1524
func TableOptionsDescriptionTransformer(tableOptions any, jsonSchema string) (schema.Transform, error) {
1625
var sc invoschema.Schema
1726
if err := json.Unmarshal([]byte(jsonSchema), &sc); err != nil {
@@ -44,9 +53,7 @@ func TableOptionsDescriptionTransformer(tableOptions any, jsonSchema string) (sc
4453
}
4554

4655
return func(table *schema.Table) error {
47-
if tableNamesToOptionsDocs[table.Name] != "" {
48-
table.Description = table.Description + "\n\n" + tableNamesToOptionsDocs[table.Name]
49-
}
56+
transformDescription(table, tableNamesToOptionsDocs)
5057
return nil
5158
}, nil
5259
}

docs/table_options_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ import (
1313
var testSchema string
1414

1515
type testTableOptions struct {
16-
Dummy testdata.DummyTableOptions `json:"dummy,omitempty"`
16+
Dummy testdata.DummyTableOptions `json:"dummy,omitempty"`
17+
Dummy2 testdata.DummyTableOptions `json:"dummy2,omitempty"`
1718
}
1819

1920
var testTable = &schema.Table{
2021
Name: "dummy",
2122
Description: "This is a dummy table",
23+
Relations: []*schema.Table{
24+
{
25+
Name: "dummy2",
26+
Description: "",
27+
},
28+
},
2229
}
2330

2431
func TestTableOptionsDescriptionTransformer(t *testing.T) {
@@ -58,6 +65,9 @@ func TestTableOptionsDescriptionTransformer(t *testing.T) {
5865
}
5966
require.NoError(t, transformer(tt.args.table))
6067
require.Equal(t, tt.wantDesc, tt.args.table.Description)
68+
for _, rel := range tt.args.table.Relations {
69+
require.NotEmpty(t, rel.Description)
70+
}
6171
})
6272
}
6373
}

0 commit comments

Comments
 (0)