Content-Length: 270773 | pFad | http://github.com/oapi-codegen/oapi-codegen/pull/1979

89 feat(output-options): add `prefer-skip-optional-pointer-on-container-types` by jamietanna · Pull Request #1979 · oapi-codegen/oapi-codegen · GitHub
Skip to content

feat(output-options): add prefer-skip-optional-pointer-on-container-types #1979

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

Merged
merged 1 commit into from
May 11, 2025

Conversation

jamietanna
Copy link
Member

@jamietanna jamietanna commented May 10, 2025

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.

It's possible for users to override this using behaviour on a per-type
or per-field basis using the x-go-type-skip-optional-pointer
extension, but there are cases, as noted in #1561, where we're
generating the optional pointer for container types (such as slices or
maps) which doesn't make sense, as it requires an extra level of
... != nil checks.

Therefore we should introduce a new opt-in Output Option to allow
skipping the optional pointer on a container type.

Closes #1561.

@jamietanna jamietanna force-pushed the issue/1561 branch 2 times, most recently from b1c0598 to 111fec8 Compare May 11, 2025 10:12
@jamietanna jamietanna changed the title feat(output-options: allow skipping optional pointer on container types feat(output-options): add prefer-skip-optional-pointer-on-container-types May 11, 2025
@jamietanna jamietanna added the enhancement New feature or request label May 11, 2025
@jamietanna jamietanna marked this pull request as ready for review May 11, 2025 10:12
@jamietanna jamietanna requested a review from a team as a code owner May 11, 2025 10:12
…types`

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.

It's possible for users to override this using behaviour on a per-type
or per-field basis using the `x-go-type-skip-optional-pointer`
extension, but there are cases, as noted in #1561, where we're
generating the optional pointer for container types (such as slices or
maps) which doesn't make sense, as it requires an extra level of
`... != nil` checks.

Therefore we should introduce a new opt-in Output Option to allow
skipping the optional pointer on a container type.

Closes #1561.
@jamietanna jamietanna merged commit 8ea9351 into main May 11, 2025
35 checks passed
@jamietanna jamietanna deleted the issue/1561 branch May 11, 2025 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't use pointer to slice of types
1 participant








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/oapi-codegen/oapi-codegen/pull/1979

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy