docs: Make null booleans falsy in the docs helper

This commit is contained in:
Bjørn Erik Pedersen
2024-01-31 12:34:28 +01:00
parent bd66d30295
commit 51615440bf
3 changed files with 18 additions and 4 deletions

View File

@@ -25,9 +25,23 @@ import (
// Regexp definitions
var (
keyMatchRegex = regexp.MustCompile(`\"(\w+)\":`)
keyMatchRegex = regexp.MustCompile(`\"(\w+)\":`)
nullEnableBoolRegex = regexp.MustCompile(`\"(enable\w+)\":null`)
)
type NullBoolJSONMarshaller struct {
Wrapped json.Marshaler
}
func (c NullBoolJSONMarshaller) MarshalJSON() ([]byte, error) {
b, err := c.Wrapped.MarshalJSON()
if err != nil {
return nil, err
}
i := bytes.Index(b, []byte("enableDefault"))
return nullEnableBoolRegex.ReplaceAll(b, []byte(`"$1": false`)), nil
}
// Code adapted from https://gist.github.com/piersy/b9934790a8892db1a603820c0c23e4a7
type LowerCaseCamelJSONMarshaller struct {
Value any