Add a toggle to disable "omitempty" #282
Draft
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.
Adding a toggle to not include the "omitempty" tag from generated struct fields.
This could be useful if you're migrating an already existing codebase which doesn't use "omitempty" to go-jsonschema and want to minimise the number of changes.
The codebase which I'm working on uses
mapstructure
and almost never usesomitempty
. Instead, it has decoder hooks to manipulate the decoding in various ways. To be honest, I think having theomitempty
might not change anything about the decoding process in my particular case. But I think having such a toggle could help make sure there are no unintended consequences from having anomitempty
.I don't think most people would want to have a
DisableOmitempty = true
though. If you usejson
oryaml
decoding, the validation functions which go-jsonschema generates wouldn't work correctly ifomitempty
is missing, since the validator wouldn't know that a non-required property is missing and it wouldn't be able to set it to its default value. My change is probably only useful for certain users ofmapstructure
.An alternative way to do this change could be to add it to goJSONSchema setting so that we can override it per property, instead of setting it globally. Maybe we should have both types of toggles - a global, and a property-specific one?