-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(output-options): allow using omitzero with prefer-skip-optional-pointer
#2023
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
Conversation
Kusari Analysis ResultsAnalysis for commit: f5165d4, performed at: 2025-07-15T12:24:25Z • • Recommendation✅ PROCEED with this Pull Request Summary✅ No Flagged Issues Detected All values appear to be within acceptable risk parameters. This PR adds dependencies only to an example directory (examples/output-options/preferskipoptionalpointerwithomitzero/go.mod), not to the main codebase. While github.com/getkin/kin-openapi@v0.128.0 has a HIGH severity vulnerability (CVE-2025-30153), this is limited to example code and doesn't affect production functionality. The security code analysis found no issues in the actual code changes. All added dependencies use permissive licenses (MIT, Apache-2.0, BSD-3-Clause, ISC). Found this helpful? Give it a 👍 or 👎 reaction! Click to expand for details and specific link to issuesDependency Changes
Security Advisoriesgithub.com/getkin/kin-openapi:
Risk Detailsgithub.com/perimeterx/marshmallow:
github.com/pmezard/go-difflib:
github.com/go-openapi/jsonpointer:
github.com/josharian/intern:
github.com/mailru/easyjson:
github.com/mohae/deepcopy:
github.com/davecgh/go-spew:
github.com/getkin/kin-openapi:
github.com/go-openapi/swag:
github.com/vmware-labs/yaml-jsonpath:
github.com/invopop/yaml:
Safe Dependency Changes
|
e2b8b59 to
3cc99f0
Compare
omitzero with prefer-skip-optional-pointer
|
Kusari PR Analysis rerun based on - 3cc99f0 performed at: 2025-07-15T12:17:44Z - link to updated analysis |
3cc99f0 to
81fc8db
Compare
|
Kusari PR Analysis rerun based on - 81fc8db performed at: 2025-07-15T12:21:04Z - link to updated analysis |
|
Kusari PR Analysis rerun based on - 220ab27 performed at: 2025-07-15T12:22:46Z - link to updated analysis |
…al-pointer` One of the key things `oapi-codegen` does is to use an "optional pointer", following idiomatic Go practices, to indicate that a field/type is optional. As noted in #1899, now Go 1.24+ has the `omitzero` JSON tag for marshaling only when a type is not its zero value. As we support generating `omitzero` JSON tags via the `x-omitzero` extension, we can build on top of this to consider allowing the use of `omitzero` when using the newly added global Output Option, `prefer-skip-optional-pointer` to tune this behaviour. This introduces a new Output Option, `prefer-skip-optional-pointer-with-omitzero`, which mirrors behaviour from `prefer-skip-optional-pointer`, but produces an `omitzero` flag for any skipped pointer types, to not marshal the type if the zero value. This allows folks using Go 1.24+ to much more ergonomically work with different (optional) types, while allowing `omitzero` to simplify (un)marshalling. Right now, we don't have a straightforward means of enforcing/warning that `oapi-codegen` is being generated into a non-Go-1.24+ project, so we'll only document the behaviour. Closes #1899.
As a follow-up from the two options we've recently introduced for this. This adds an anchor so we can reference it more easily than the GitHub-generated name for the long heading.
220ab27 to
f5165d4
Compare
|
Kusari PR Analysis rerun based on - f5165d4 performed at: 2025-07-15T12:24:25Z - link to updated analysis |
…-optional-pointer` We should have rebased #2023 before this was merged, as the versions were outdated.
One of the key things
oapi-codegendoes is to use an "optionalpointer", following idiomatic Go practices, to indicate that a
field/type is optional.
As noted in #1899, now Go 1.24+ has the
omitzeroJSON tag formarshaling only when a type is not its zero value.
As we support generating
omitzeroJSON tags via thex-omitzeroextension, we can build on top of this to consider allowing the use of
omitzerowhen using the newly added global Output Option,prefer-skip-optional-pointerto tune this behaviour.This introduces a new Output Option,
prefer-skip-optional-pointer-with-omitzero, which mirrors behaviourfrom
prefer-skip-optional-pointer, but produces anomitzeroflag forany skipped pointer types, to not marshal the type if the zero value.
This allows folks using Go 1.24+ to much more ergonomically work with
different (optional) types, while allowing
omitzeroto simplify(un)marshalling.
Right now, we don't have a straightforward means of enforcing/warning
that
oapi-codegenis being generated into a non-Go-1.24+ project, sowe'll only document the behaviour.
Closes #1899.