Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsZero() panics with nil *strfmt.DateTime #66

Closed
amadorcervera opened this issue Mar 17, 2023 · 0 comments · Fixed by #67
Closed

IsZero() panics with nil *strfmt.DateTime #66

amadorcervera opened this issue Mar 17, 2023 · 0 comments · Fixed by #67

Comments

@amadorcervera
Copy link

amadorcervera commented Mar 17, 2023

I have a swagger specification with an object that has an optional string property with date-time format. The code generated for this field is:

NotAfter *strfmt.DateTime `json:"not_after,omitempty"`

and the validation function generated:

func (m *SigningProfile) validateNotAfter(formats strfmt.Registry) error {
	if swag.IsZero(m.NotAfter) { // not required
		return nil
	}

	if err := validate.FormatOf("not_after", "body", "date-time", m.NotAfter.String(), formats); err != nil {
		return err
	}

	return nil
}

When this field is not set, that is when is nil, the call to swag.IsZero() panics:

panic: value method github.com/go-openapi/strfmt.DateTime.IsZero called using nil *DateTime pointer

My code hasn't been modified in months and it was working perfectly few days ago. I think the problem could be related with the changes from this commit in strfmt: Adds IsZero functionality to DateTime and the beginning of the IsZero() function:

func IsZero(data interface{}) bool {
	// check for things that have an IsZero method instead
	if vv, ok := data.(zeroable); ok {
		return vv.IsZero()
	}

because now strfmt.DateTime is zeroable. Previously should go through this case in the switch:

	case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
		return v.IsNil()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant