Skip to content

Support nullable slice elements and map values#2185

Merged
mromaszewicz merged 1 commit intooapi-codegen:mainfrom
iamtakingiteasy:support-nullable-vectors
Feb 17, 2026
Merged

Support nullable slice elements and map values#2185
mromaszewicz merged 1 commit intooapi-codegen:mainfrom
iamtakingiteasy:support-nullable-vectors

Conversation

@iamtakingiteasy
Copy link
Contributor

@iamtakingiteasy iamtakingiteasy commented Jan 20, 2026

Adds support for nullable slice elements, e.g. []*string, if items are declared as nullable: true (analogous to map[string]*string if additionalProperties is having nullable: true and to fields describing/referencing nullable types), allows handling of values like ["a", null, null, "d", ""] and occasionally improves the UX with DTO processing.

Closes #158
Based on and re-implements #158-specific portion of #490, also with tests for the map case and none of the unrelated changes.

@iamtakingiteasy iamtakingiteasy requested a review from a team as a code owner January 20, 2026 07:32
@iamtakingiteasy iamtakingiteasy force-pushed the support-nullable-vectors branch from 7fd08d0 to bf89b07 Compare January 20, 2026 07:38
@iamtakingiteasy
Copy link
Contributor Author

iamtakingiteasy commented Jan 20, 2026

Sorted testcases by nullability.

@mromaszewicz
Copy link
Member

For nullable types, we have a Nullable[T], so I wonder if it makes sense to use Nullables or pointers. I see that someone added nullable support to maps via the pointer type, so this would be similar to that, while we use the Nullable wrapper in other cases. I don't like that we have two ways of doing this. It's too late now, though.

@mromaszewicz
Copy link
Member

Once you rebase and CI runs, this should be submittable.

@mromaszewicz mromaszewicz force-pushed the support-nullable-vectors branch from bf89b07 to 5f2964f Compare February 17, 2026 03:16
@mromaszewicz mromaszewicz merged commit f4ac5df into oapi-codegen:main Feb 17, 2026
26 checks passed
@iamtakingiteasy
Copy link
Contributor Author

Regarding, Nullable[T], it may be useful for isolated values, allowing to distinguish the tri-state, but there is still the need to represent regular slices and maps where bi-state suffices and requires no overhead, allowing to make use of generated models in regular go code, where mutability of slice/map elements may be desired, which may be the case even during request/response construction.

@jamietanna
Copy link
Member

jamietanna commented Feb 24, 2026

This appears to cause a regression - rootlyhq/rootly-go#41 is now receiving i.e.

 type Alert struct {
        // AlertFieldValuesAttributes Custom alert field values to create with the alert
-       AlertFieldValuesAttributes []struct {
+       AlertFieldValuesAttributes []*struct {

When using prefers-skip-optional-pointer

@jamietanna
Copy link
Member

jamietanna commented Feb 24, 2026

As discussed in #2240, this wasn't actually an issue for Rootly's API

However, I don't know if this behaviour is correct when using the nullable.Nullable type?

Edit: I've raised #2242

jamietanna added a commit that referenced this pull request Feb 24, 2026
As a follow-up to #2185, we can make sure we generate a Nullable type if
required to do so.
jamietanna added a commit that referenced this pull request Feb 24, 2026
As a follow-up to #2185, we can make sure we generate a Nullable type if
required to do so.
jamietanna added a commit that referenced this pull request Feb 24, 2026
As a follow-up to #2185, we can make sure we generate a Nullable type if
required to do so.
@jamietanna jamietanna added the enhancement New feature or request label Feb 27, 2026
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.

Checking for the *[] vs []*

3 participants