Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support omitempty on non-optionalproperties #8

Open
docktermj opened this issue Jul 3, 2023 · 0 comments
Open

Support omitempty on non-optionalproperties #8

docktermj opened this issue Jul 3, 2023 · 0 comments

Comments

@docktermj
Copy link

First of all, nice work on json-typedef! Exactly what I need for a project.

I know that by using optionalProperties, the Go type-structs generated will include omitempty in the structure's JSON annotation.

However, there are times in Go when a member of properties would also benefit from the addition of omitempty when Marshaling the structure back into JSON.

A potential solution: Support an additional metadata key/value for the Go language, perhaps goOmitempty, to allow the user to indicate that omitempty is desired in the JSON annotation for a specific JSON key. (Similar to the goType key in metadata.) Feel free to improve on this idea.

Perhaps I've missed an existing solution to this, I'm aware of the items seen in the "References" section, but that's about it. Please let me know if there is an existing solution.

Thank you for your consideration.

References:

  1. https://jsontypedef.com/docs/go-codegen/#code-generated-from-properties-schemas
  2. https://github.com/jsontypedef/json-typedef-codegen#advanced-usage-customizing-jtd-codegen-output
  3. https://github.com/search?q=org%3Ajsontypedef%20omitempty&type=code
    1. https://github.com/jsontypedef/jsontypedef.com/blob/6c2364c3b9f15b7ffce7b2078dc96ac0af283006/content/docs/go-codegen.md?plain=1#L409
    2. https://github.com/jsontypedef/json-typedef-codegen/blob/a42555df78cef014e3153c07edf13bd9d00fe8e9/crates/target_go/src/lib.rs#L229
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

No branches or pull requests

1 participant