Skip to content

Tags: oapi-codegen/nullable

Tags

v1.1.0

Toggle v1.1.0's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Add `MustGet` function (#2)

In the cases where a user has explicitly checked `IsSpecified()` and
`!IsNull()`, calling `Get` only to discard the `err` can be a bit
awkward, so instead we can introduce a `MustGet` method to retrieve the
value and panic if there is an error, as is common to do with Go
libraries.

v1.0.1

Toggle v1.0.1's commit message
docs: correct README code for optional

v1.0.0

Toggle v1.0.0's commit message
Implement `oapi-codegen/nullable`

This bootstraps a new repository for the `oapi-codegen` organisation's
standards, and then implements the `Nullable` type as per [0] and [1].

Using a `map` as the underlying type allows us to take advantage of
`json.Marshal`'s inbuilt checks to determine whether to `omitempty` a
JSON value, which isn't possible with a `struct`.

We can make sure this is a multi-module project, similar to
other projects, so we can isolate test-only dependencies from the core
project, which has zero dependencies.

We can also add convenience helpers for `NewNullableWithValue` and
`NewNullNullable` as they can be useful when constructing `struct`s in
tests.

In the top-level project we can use runnable examples to indicate the
example usage and cover all the test cases we need, and then use the
`internal/test` package to perform further checks.

Co-authored-by: Sebastien Guilloux <[email protected]>
Co-authored-by: Ashutosh Kumar <[email protected]>

[0]: golang/go#64515 (comment)
[1]: https://github.com/sebgl/nullable/