bump backend go deps

This commit is contained in:
Ronni Skansing
2025-09-15 19:41:59 +02:00
parent b905117ab9
commit 1ea5433829
2960 changed files with 1446680 additions and 6 deletions
@@ -0,0 +1 @@
/bin
+13
View File
@@ -0,0 +1,13 @@
Copyright 2024 oapi-codegen
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+28
View File
@@ -0,0 +1,28 @@
GOBASE=$(shell pwd)
GOBIN=$(GOBASE)/bin
help:
@echo "This is a helper makefile for oapi-codegen"
@echo "Targets:"
@echo " test: run all tests"
@echo " tidy tidy go mod"
@echo " lint run linting"
$(GOBIN)/golangci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.55.2
.PHONY: tools
tools: $(GOBIN)/golangci-lint
lint: tools
git ls-files go.mod '**/*go.mod' -z | xargs -0 -I{} bash -xc 'cd $$(dirname {}) && $(GOBIN)/golangci-lint run ./...'
lint-ci: tools
git ls-files go.mod '**/*go.mod' -z | xargs -0 -I{} bash -xc 'cd $$(dirname {}) && $(GOBIN)/golangci-lint run ./... --out-format=github-actions --timeout=5m'
test:
git ls-files go.mod '**/*go.mod' -z | xargs -0 -I{} bash -xc 'cd $$(dirname {}) && go test -cover ./...'
tidy:
@echo "tidy..."
git ls-files go.mod '**/*go.mod' -z | xargs -0 -I{} bash -xc 'cd $$(dirname {}) && go mod tidy'
+48
View File
@@ -0,0 +1,48 @@
# oapi-codegen/nullable
> An implementation of a `Nullable` type 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:
```go
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](https://github.com/oapi-codegen) for the `oapi-codegen` OpenAPI-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:
```sh
go get github.com/oapi-codegen/nullable
```
Check out the examples in [the package documentation on pkg.go.dev](https://pkg.go.dev/github.com/oapi-codegen/nullable) for more details.
## Credits
- [KumanekoSakura](https://github.com/KumanekoSakura), [via](https://github.com/golang/go/issues/64515#issuecomment-1842973794)
- [Sebastien Guilloux](https://github.com/sebgl), [via](https://github.com/sebgl/nullable/)
As well as contributions from:
- [Jamie Tanna](https://www.jvt.me)
- [Ashutosh Kumar](https://github.com/sonasingh46)
## License
Licensed under the Apache-2.0 license.
+117
View File
@@ -0,0 +1,117 @@
package nullable
import (
"bytes"
"encoding/json"
"errors"
)
// Nullable is a generic type, which implements a field that can be one of three states:
//
// - field is not set in the request
// - field is explicitly set to `null` in the request
// - field is explicitly set to a valid value in the request
//
// Nullable is intended to be used with JSON marshalling and unmarshalling.
//
// Internal implementation details:
//
// - map[true]T means a value was provided
// - map[false]T means an explicit null was provided
// - nil or zero map means the field was not provided
//
// If the field is expected to be optional, add the `omitempty` JSON tags. Do NOT use `*Nullable`!
//
// Adapted from https://github.com/golang/go/issues/64515#issuecomment-1841057182
type Nullable[T any] map[bool]T
// NewNullableWithValue is a convenience helper to allow constructing a `Nullable` with a given value, for instance to construct a field inside a struct, without introducing an intermediate variable
func NewNullableWithValue[T any](t T) Nullable[T] {
var n Nullable[T]
n.Set(t)
return n
}
// NewNullNullable is a convenience helper to allow constructing a `Nullable` with an explicit `null`, for instance to construct a field inside a struct, without introducing an intermediate variable
func NewNullNullable[T any]() Nullable[T] {
var n Nullable[T]
n.SetNull()
return n
}
// Get retrieves the underlying value, if present, and returns an error if the value was not present
func (t Nullable[T]) Get() (T, error) {
var empty T
if t.IsNull() {
return empty, errors.New("value is null")
}
if !t.IsSpecified() {
return empty, errors.New("value is not specified")
}
return t[true], nil
}
// MustGet retrieves the underlying value, if present, and panics if the value was not present
func (t Nullable[T]) MustGet() T {
v, err := t.Get()
if err != nil {
panic(err)
}
return v
}
// Set sets the underlying value to a given value
func (t *Nullable[T]) Set(value T) {
*t = map[bool]T{true: value}
}
// IsNull indicate whether the field was sent, and had a value of `null`
func (t Nullable[T]) IsNull() bool {
_, foundNull := t[false]
return foundNull
}
// SetNull indicate that the field was sent, and had a value of `null`
func (t *Nullable[T]) SetNull() {
var empty T
*t = map[bool]T{false: empty}
}
// IsSpecified indicates whether the field was sent
func (t Nullable[T]) IsSpecified() bool {
return len(t) != 0
}
// SetUnspecified indicate whether the field was sent
func (t *Nullable[T]) SetUnspecified() {
*t = map[bool]T{}
}
func (t Nullable[T]) MarshalJSON() ([]byte, error) {
// if field was specified, and `null`, marshal it
if t.IsNull() {
return []byte("null"), nil
}
// if field was unspecified, and `omitempty` is set on the field's tags, `json.Marshal` will omit this field
// otherwise: we have a value, so marshal it
return json.Marshal(t[true])
}
func (t *Nullable[T]) UnmarshalJSON(data []byte) error {
// if field is unspecified, UnmarshalJSON won't be called
// if field is specified, and `null`
if bytes.Equal(data, []byte("null")) {
t.SetNull()
return nil
}
// otherwise, we have an actual value, so parse it
var v T
if err := json.Unmarshal(data, &v); err != nil {
return err
}
t.Set(v)
return nil
}