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

@lzap lzap 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 owner March 20, 2025 11:04
Comment thread nullable.go Outdated
@jamietanna jamietanna self-assigned this Feb 17, 2026
@jamietanna jamietanna linked an issue Feb 17, 2026 that may be closed by this pull request
@jamietanna jamietanna requested a review from mromaszewicz June 21, 2026 17:06
@lzap

lzap commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebased, renamed to GetOrEmpty

@mromaszewicz mromaszewicz enabled auto-merge June 22, 2026 14:29
@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:main Jun 22, 2026
8 checks passed
@mromaszewicz mromaszewicz added the enhancement New feature or request label Jun 22, 2026
@lzap lzap deleted the dig1 branch June 23, 2026 07:59
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.

feat: add GetOrZero

4 participants