want:=&GroupLabel{ID:5,Name:"kind/bug",Color:"#d9534f",Description:"Bug reported by user",OpenIssuesCount:1,ClosedIssuesCount:0,OpenMergeRequestsCount:1,Subscribed:true}
want:=&GroupLabel{ID:5,Name:"kind/bug",Color:"#d9534f",Description:"Bug reported by user",OpenIssuesCount:1,ClosedIssuesCount:0,OpenMergeRequestsCount:1,Subscribed:true,Priority:NewNullNullable[int64]()}
if!reflect.DeepEqual(want,label){
t.Errorf("GroupLabels.SubscribeToGroupLabel returned %+v, want %+v",label,want)
t.Log(err.Error()=="invalid ID type 1.1, the ID must be an int64 or a string")
}
want:=[]*GroupLabel{{ID:5,Name:"kind/bug",Color:"#d9534f",Description:"Bug reported by user",OpenIssuesCount:1,ClosedIssuesCount:0,OpenMergeRequestsCount:1,Subscribed:true}}
want:=[]*GroupLabel{{ID:5,Name:"kind/bug",Color:"#d9534f",Description:"Bug reported by user",OpenIssuesCount:1,ClosedIssuesCount:0,OpenMergeRequestsCount:1,Subscribed:true,Priority:NewNullNullable[int64]()}}
if!reflect.DeepEqual(want,label){
t.Errorf("GroupLabels.ListGroupLabels returned %+v, want %+v",label,want)
want:=&GroupLabel{ID:5,Name:"kind/bug",Color:"#d9534f",Description:"Bug reported by user",OpenIssuesCount:1,ClosedIssuesCount:0,OpenMergeRequestsCount:1,Subscribed:true}
want:=&GroupLabel{ID:5,Name:"kind/bug",Color:"#d9534f",Description:"Bug reported by user",OpenIssuesCount:1,ClosedIssuesCount:0,OpenMergeRequestsCount:1,Subscribed:true,Priority:NewNullNullable[int64]()}
if!reflect.DeepEqual(want,label){
t.Errorf("GroupLabels.GetGroupLabel returned %+v, want %+v",label,want)
want:=&Label{ID:5,Name:"kind/bug",Color:"#d9534f",Description:"Bug reported by user",OpenIssuesCount:1,ClosedIssuesCount:0,OpenMergeRequestsCount:1,Subscribed:true}
want:=&Label{ID:5,Name:"kind/bug",Color:"#d9534f",Description:"Bug reported by user",OpenIssuesCount:1,ClosedIssuesCount:0,OpenMergeRequestsCount:1,Subscribed:true,Priority:NewNullNullable[int64]()}
if!reflect.DeepEqual(want,label){
t.Errorf("Labels.SubscribeToLabel returned %+v, want %+v",label,want)
t.Log(err.Error()=="invalid ID type 1.1, the ID must be an int or a string")
}
want:=[]*Label{{ID:5,Name:"kind/bug",Color:"#d9534f",Description:"Bug reported by user",OpenIssuesCount:1,ClosedIssuesCount:0,OpenMergeRequestsCount:1,Subscribed:true}}
want:=[]*Label{{ID:5,Name:"kind/bug",Color:"#d9534f",Description:"Bug reported by user",OpenIssuesCount:1,ClosedIssuesCount:0,OpenMergeRequestsCount:1,Subscribed:true,Priority:NewNullNullable[int64]()}}
if!reflect.DeepEqual(want,label){
t.Errorf("Labels.ListLabels returned %+v, want %+v",label,want)
want:=&Label{ID:5,Name:"kind/bug",Color:"#d9534f",Description:"Bug reported by user",OpenIssuesCount:1,ClosedIssuesCount:0,OpenMergeRequestsCount:1,Subscribed:true}
want:=&Label{ID:5,Name:"kind/bug",Color:"#d9534f",Description:"Bug reported by user",OpenIssuesCount:1,ClosedIssuesCount:0,OpenMergeRequestsCount:1,Subscribed:true,Priority:NewNullNullable[int64]()}
if!reflect.DeepEqual(want,label){
t.Errorf("Labels.GetLabel returned %+v, want %+v",label,want)
// 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.
//
// This code was adapted from https://github.com/oapi-codegen/nullable
//
packagegitlab
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 marshaling and unmarshaling.
//
// 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
typeNullable[Tany]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
funcNewNullableWithValue[Tany](tT)Nullable[T]{
varnNullable[T]
n.Set(t)
returnn
}
// 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
funcNewNullNullable[Tany]()Nullable[T]{
varnNullable[T]
n.SetNull()
returnn
}
// Get retrieves the underlying value, if present, and returns an error if the value was not present
func(tNullable[T])Get()(T,error){
varemptyT
ift.IsNull(){
returnempty,errors.New("value is null")
}
if!t.IsSpecified(){
returnempty,errors.New("value is not specified")
}
returnt[true],nil
}
// MustGet retrieves the underlying value, if present, and panics if the value was not present
func(tNullable[T])MustGet()T{
v,err:=t.Get()
iferr!=nil{
panic(err)
}
returnv
}
// Set sets the underlying value to a given value
func(t*Nullable[T])Set(valueT){
*t=map[bool]T{true:value}
}
// IsNull indicate whether the field was sent, and had a value of `null`
func(tNullable[T])IsNull()bool{
_,foundNull:=t[false]
returnfoundNull
}
// SetNull indicate that the field was sent, and had a value of `null`
func(t*Nullable[T])SetNull(){
varemptyT
*t=map[bool]T{false:empty}
}
// IsSpecified indicates whether the field was sent
func(tNullable[T])IsSpecified()bool{
returnlen(t)!=0
}
// SetUnspecified indicate whether the field was sent
func(t*Nullable[T])SetUnspecified(){
*t=map[bool]T{}
}
func(tNullable[T])MarshalJSON()([]byte,error){
// if field was specified, and `null`, marshal it
ift.IsNull(){
return[]byte("null"),nil
}
// if field was unspecified, and `omitempty` is set on the field's tags, `json.Marshal` will omit this field