Skip to content

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
karimkhaleel:key-namer-with-original-name
Open

Extra KeyNamer-like function that takes in name extraced from tag + origingal go field name#164
karimkhaleel wants to merge 2 commits intoinvopop:mainfrom
karimkhaleel:key-namer-with-original-name

Conversation

@karimkhaleel
Copy link
Copy Markdown

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 OriginalPropertiesMapping map onto the Schema struct 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 the Schema struct.

This PR uses a different approach, where a KeyNamerWithOriginalFieldName func(string, string) string can be specified on the Reflector struct that gets called in a similar manner to KeyNamer. KeyNamer takes precedence over KeyNamerWithOriginalFieldName.

This approach would allow us to extract the relationship between tag names and go field names while avoiding polluting the Schema struct 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.

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.

1 participant