jesseduffield / jesseduffield/lazygit
JSONSchema: using a different approach for setting default userconfig values
- Dominant language
- Go
- Stars
- 82.4k
- Forks
- 3k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 19
Description
**Topic**
JSONSchema generation
**Your thoughts**
When we generate our jsonschema we need to preserve the mapping between our original go struct field names and the yaml names they get renamed to. This is done so that we can fill in the jsonschema default values from our default config object.
In order to preserve that relationship I made a [fork](https://github.com/karimkhaleel/jsonschema/tree/main-lazygit) of [invopop/jsonschema](https://github.com/invopop/jsonschema/), that attaches an additional `OriginalPropertiesMapping` field to the `Schema` struct. This solves our problem but adds a non jsonschema field onto the `Schema` struct of the jsonschema library. I don't think that this is an elegant approach and think that I came up with a better one.
I found a different way of preserving the relationship that we need during the reflection phase of the schema generation. Instead of storing that relationship on the `Schema` object, we can expose both the original go field name and the yaml tag name with a function similar to `KeyNamer`.
[This](https://github.com/invopop/jsonschema/commit/218dcff5fddbeb277a0454bd3f9a6d4c0c652ecb) + [Tests](https://github.com/invopop/jsonschema/commit/8dc70c94106f15efac229d48cf610a3b47213351) would still need to get merged into the official jsonschema repo. But I think this is a more reasonable approach than the initial one I made a [PR](https://github.com/invopop/jsonschema/pull/117) for earlier.
We would also need to make some changes on our end. [This](https://github.com/jesseduffield/lazygit/pull/4418) is what we would need to change our code to use the `KeyNamerWithOriginalFieldName` function to record the relationship between original go field names and the yaml tag names that they get exported as.
Contributor guide
Assessment
This issue has not been assessed yet.