Skip to content

Commit

Permalink
Add Model references to Interface (#2738)
Browse files Browse the repository at this point in the history
  • Loading branch information
penard-cb authored Aug 1, 2023
1 parent 790d7a7 commit 2d8673a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions plugin/modelgen/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Interface struct {
Fields []*Field
Implements []string
OmitCheck bool
Models []*Object
}

type Object struct {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2d8673a

Please sign in to comment.