Extra KeyNamer-like function that takes in name extraced from tag + origingal go field name#164
Open
karimkhaleel wants to merge 2 commits intoinvopop:mainfrom
Open
Extra KeyNamer-like function that takes in name extraced from tag + origingal go field name#164karimkhaleel wants to merge 2 commits intoinvopop:mainfrom
karimkhaleel wants to merge 2 commits intoinvopop:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Over at lazygit, we use jsonschema to automatically generate our user config schema. We need to populate the schema with default values that we set at runtime here. In order to do that, we need to preserve a relationship of the tag name to go struct name, like in this example:
git -> Git. It would be very convenient if we could somehow hook into jsonschema's reflection process and preserve that relationship.Earlier, I submitted a PR that attached an
OriginalPropertiesMappingmap onto theSchemastruct that would store the mapping of tag name -> original go field name. This approach works for us, since we can access it on the Schema nodes during our default values population phase, but adds a non jsonschema field to theSchemastruct.This PR uses a different approach, where a
KeyNamerWithOriginalFieldName func(string, string) stringcan be specified on theReflectorstruct that gets called in a similar manner toKeyNamer.KeyNamertakes precedence overKeyNamerWithOriginalFieldName.This approach would allow us to extract the relationship between tag names and go field names while avoiding polluting the
Schemastruct with non jsonschema fields.Also open to suggestions on how we could extract this relationship without adding anything to the upstream repo, but so far I haven't been able to see an obvious way to do that.