You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The switch to pointer receivers to fix #106 broke YAML marshalling of strfmt.DateTime when used with a omitempty value field.
Repro:
package main
import (
"fmt"
"time"
"github.com/go-openapi/strfmt"
"gopkg.in/yaml.v3"
)
type S struct {
Name string `yaml:"name"`
Created strfmt.DateTime `yaml:"created,omitempty"`
}
func main() {
s := S{
Name: "test",
Created: strfmt.DateTime(time.Now()),
}
marshalled, err := yaml.Marshal(s)
if err != nil {
panic(err)
}
fmt.Println(string(marshalled))
}
With 0.21.5, the output of the above is:
name: test
created: "2025-01-09T16:13:43.220-08:00"
With 0.21.6, and all newer versions including 0.23.0, the output is:
name: test
(no output for created).
The primary reason is that when the field is specified as a value, only value methods can be called.
The fix was originally added to because swag.IsZero did not handle pointer, but that was fixed in go-openapi/swag#67 so I think the the IsZero method should be moved back to the value.
The text was updated successfully, but these errors were encountered:
prashantv
added a commit
to prashantv/strfmt
that referenced
this issue
Jan 10, 2025
The switch to pointer receivers to fix #106 broke YAML marshalling of
strfmt.DateTime
when used with aomitempty
value field.Repro:
With 0.21.5, the output of the above is:
With 0.21.6, and all newer versions including 0.23.0, the output is:
(no output for
created
).The primary reason is that when the field is specified as a value, only value methods can be called.
The fix was originally added to because
swag.IsZero
did not handle pointer, but that was fixed in go-openapi/swag#67 so I think the theIsZero
method should be moved back to the value.The text was updated successfully, but these errors were encountered: