Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix adding duplicate fields when they are coming from an extended class #78

Merged
merged 2 commits into from
Feb 11, 2023

Conversation

spinillos
Copy link
Member

Fixes: https://github.com/grafana/schematization-and-as-code-project/issues/64

The main issue was the way that we are unifying the values in nolit. Executing Unify itself, it adds extra nested levels for every new value. It only "detects" the nested value as an extended interface and its why it only works with the last value defined.

For any reason, use an empty Value to generate the tree does the trick πŸ€·πŸ»β€β™€οΈ.

More "visual" example should be:

A: {
  B
  C
  D
}

B: {
 b: string
}

C: {
  c: string
}

D: {
  d: string
}

It was generating:

:
(struct)

:
[&]  (struct)
β”œβ”€β”€ (struct)
└── (struct)

:
[&]  _|_
β”œβ”€β”€ [&]  (struct)
β”‚   β”œβ”€β”€ (struct)
β”‚   └── (struct)
└── (struct)

:
[&]  _|_
β”œβ”€β”€ [&]  (struct)
β”‚   β”œβ”€β”€ [&]  (struct)
β”‚   β”‚   β”œβ”€β”€ (struct)
β”‚   β”‚   └── (struct)
β”‚   └── (struct)
└── (struct)

Now:

:
(struct)

:
[&]  (struct)
β”œβ”€β”€ (struct)
└── [&]  (struct)
    β”œβ”€β”€ (struct)
    └── (struct)

:
[&]  (struct)
β”œβ”€β”€ (struct)
└── [&]  (struct)
    β”œβ”€β”€ [&]  (struct)
    β”‚   β”œβ”€β”€ (struct)
    β”‚   └── [&]  (struct)
    β”‚       β”œβ”€β”€ (struct)
    β”‚       └── (struct)
    └── (struct)

:
[&]  (struct)
β”œβ”€β”€ (struct)
└── [&]  (struct)
    β”œβ”€β”€ [&]  (struct)
    β”‚   β”œβ”€β”€ (struct)
    β”‚   └── [&]  (struct)
    β”‚       β”œβ”€β”€ [&]  (struct)
    β”‚       β”‚   β”œβ”€β”€ (struct)
    β”‚       β”‚   └── [&]  (struct)
    β”‚       β”‚       β”œβ”€β”€ (struct)
    β”‚       β”‚       └── (struct)
    β”‚       └── (struct)
    └── (struct)

So BottomKind disappears.

Copy link
Contributor

@sdboyer sdboyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure i quite grok why this fixed it, but clearly it did :)

generator.go Outdated Show resolved Hide resolved
@sdboyer sdboyer merged commit e938b68 into main Feb 11, 2023
@sdboyer sdboyer deleted the fix-duplicate-fields branch February 11, 2023 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants