Nullable
An implementation of a `Nullable` type for JSON bodies, indicating whether the field is absent, set to null, or set to a value
Install / Use
/learn @oapi-codegen/NullableREADME
oapi-codegen/nullable
An implementation of a
Nullabletype for JSON bodies, indicating whether the field is absent, set to null, or set to a value
Unlike other known implementations, this makes it possible to both marshal and unmarshal the value, as well as represent all three states:
- the field is not set
- the field is explicitly set to null
- the field is explicitly set to a given value
And can be embedded in structs, for instance with the following definition:
obj := struct {
// RequiredID is a required, nullable field
RequiredID nullable.Nullable[int] `json:"id"`
// OptionalString is an optional, nullable field
// NOTE that no pointer is required, only `omitempty`
OptionalString nullable.Nullable[string] `json:"optionalString,omitempty"`
}{}
Usage
[!IMPORTANT] Although this project is under the oapi-codegen org for the
oapi-codegenOpenAPI-to-Go code generator, this is intentionally released as a separate, standalone library which can be used by other projects.
First, add to your project with:
go get github.com/oapi-codegen/nullable
Check out the examples in the package documentation on pkg.go.dev for more details.
Credits
As well as contributions from:
License
Licensed under the Apache-2.0 license.
Related Skills
node-connect
344.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
96.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
