Skip to content

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

2 participants