Skip to content

feat: new method for fetching ignoring error - #13

Merged
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
lzap:dig1
Jun 22, 2026
Merged

feat: new method for fetching ignoring error#13
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
lzap:dig1

Conversation

@lzap

@lzaplzap commented Mar 20, 2025

Copy link
Copy Markdown
Contributor

This may sound crazy, but I am working on a codebase where we use OpenAPI schema to describe a (YAML) document. All fields (except document name) are optional so I have to work with many optional fiels. While I want to explore the new feature omitzero, I am evaluating nullable to do the heavylifting and I am not even sure if this is gonna work yet.

But I would love to have a method - workting title - Dig that does exactly what Get does but ignores the error and returns an empty value. Assuming that all fields within structs are also treated with nullable my theory is this can simulate behavior of omitzero.

a:=value.Field.Dig().Field.Dig()

Am I crazy? I think I am. Well, let’s hear from others. I am unsure about the name for such method, but I want something that is short so I came up with Dig which is probably too wild. But GetWithoutError would not work that is way too long. Also this does not have tests yet because I am unsure if you like this or if there are not flaws in my idea.

@lzap
lzap requested a review from a team as a code ownerMarch 20, 2025 11:04
Comment threadnullable.go Outdated
@jamietannajamietanna self-assigned this Feb 17, 2026
@jamietannajamietanna linked an issue Feb 17, 2026 that may be closed by this pull request
@lzap

lzap commented Jun 22, 2026

Copy link
Copy Markdown
ContributorAuthor

Rebased, renamed to GetOrEmpty

@mromaszewicz

Copy link
Copy Markdown
Member

Oh, the CI is rotten in this repo. It needs an update. I'll force commit this. CI did pass, but it's not being picked up.

@mromaszewicz
mromaszewicz disabled auto-merge June 22, 2026 14:31
@mromaszewicz
mromaszewicz merged commit e578825 into oapi-codegen:mainJun 22, 2026
8 checks passed
@mromaszewiczmromaszewicz added the enhancement New feature or request label Jun 22, 2026
@lzap
lzap deleted the dig1 branch June 23, 2026 07:59
mromaszewicz added a commit to frenchi/nullable that referenced this pull request Aug 6, 2026
Brings the branch up to date with main, which has since gained
`Nullable.GetOrEmpty()` (oapi-codegen#13) and the consolidated CI workflow /
golangci-lint v2 Makefile changes (oapi-codegen#33).
No textual conflicts: `GetOrEmpty` landed on `Nullable` while this
branch's new `Value[T]` methods were appended above it, so both sides'
additions are preserved as-is.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancementNew feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add GetOrZero

4 participants

@lzap@mromaszewicz@0rid@jamietanna