From 2d8673a691deffe6ddd1f4d5f013a52dc91aef91 Mon Sep 17 00:00:00 2001 From: penard-cb <135390596+penard-cb@users.noreply.github.com> Date: Tue, 1 Aug 2023 15:39:05 -0400 Subject: [PATCH] Add Model references to Interface (#2738) --- plugin/modelgen/models.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin/modelgen/models.go b/plugin/modelgen/models.go index 23c2e334d9..bbf599d6ed 100644 --- a/plugin/modelgen/models.go +++ b/plugin/modelgen/models.go @@ -52,6 +52,7 @@ type Interface struct { Fields []*Field Implements []string OmitCheck bool + Models []*Object } type Object struct { @@ -200,6 +201,15 @@ func (m *Plugin) MutateConfig(cfg *config.Config) error { cfg.Models.Add(it.Name, cfg.Model.ImportPath()+"."+templates.ToGo(it.Name)) } for _, it := range b.Interfaces { + // On a given interface we want to keep a reference to all the models that implement it + for _, model := range b.Models { + for _, impl := range model.Implements { + if impl == it.Name { + // If it does, add it to the Interface's Models + it.Models = append(it.Models, model) + } + } + } cfg.Models.Add(it.Name, cfg.Model.ImportPath()+"."+templates.ToGo(it.Name)) } for _, it := range b.Scalars {