Skip to content

Set SkipOptionalPointer for array types#388

Closed
natsukagami wants to merge 1 commit intooapi-codegen:masterfrom
curvegrid:make-array-indirection-optional
Closed

Set SkipOptionalPointer for array types#388
natsukagami wants to merge 1 commit intooapi-codegen:masterfrom
curvegrid:make-array-indirection-optional

Conversation

@natsukagami
Copy link
Copy Markdown
Contributor

Brief Description of Changes

Set the SkipOptionalPointer property to true for all array schema types.

Effectively, this means an optional []int still has type []int, instead of the old *[]int.

Rationale

I don't find any functional difference in treating an []int and an *[]int. See:

They both:

  • Can disambiguate between absent field (nil value) and empty array case (where both are non-nil).
  • Cannot disambiguate between absent field and NULL value.

On the other hand, *[]T are much more clumsy to work with, due to the additional referencing/dereferencing
required.

Some libraries that rely on the polymorphic behaviour of len (on arrays and maps) cannot be used,
forcing the user to check for nil and dereferencing the *[]T as input.
ozzo-validaion's Length check is one of them.

Breaking Change

Yes, this is a breaking change (it functionally changes some test examples).

However, I believe this makes the user experience much better.

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

Successfully merging this pull request may close these issues.

1 participant