omissis/go-jsonschema

Feature request: support configuring generated struct tags

codeboten opened this issue · 5 comments

Currently the generated code always sets a struct tag for json, yaml, and mapstructure. See:

if isRequired {
structField.Tags = fmt.Sprintf(`json:"%s" yaml:"%s" mapstructure:"%s"`, name, name, name)
} else {
structField.Tags = fmt.Sprintf(`json:"%s,omitempty" yaml:"%s,omitempty" mapstructure:"%s,omitempty"`,
name, name, name)

It would be great if it was possible to pass in a configuration option to specify which of these to set.

Hi @codeboten, thanks for raising this issue and for contributing the PR! Question: do those unused, extra tags cause issues in downstream code, or is this change done for "cosmetic" purposes only?

@omissis the request came from this comment open-telemetry/opentelemetry-collector#7679 (comment). The rest of the code for the configuration for the collector only contains mapstructure struct tags, so i think this is mostly for consistency

I see, thanks. I'll ask on that PR and I will take a look over the weekend

@omissis any thoughts on whether the PR for this feature can get merged?

@codeboten yeah I asked on the pr some clarifications, and I'm ok with offloading some maintenance off them to have it here, even though I feel the command interface is becoming a bit bloated. I'll see to review this PR as soon as possible. Thanks!