// Code generated by go-swagger; DO NOT EDIT. package models // This file was generated by the swagger tool. // Editing this file might prove futile when you re-run the swagger generate command import ( "context" "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" "github.com/go-openapi/validate" ) // FilterV1 FilterV1 represents a user-defined filter for determining which statuses should not be shown to the user. // // Note that v1 filters are mapped to v2 filters and v2 filter keywords internally. // If whole_word is true, client app should do: // Define ‘word constituent character’ for your app. In the official implementation, it’s [A-Za-z0-9_] in JavaScript, and [[:word:]] in Ruby. // Ruby uses the POSIX character class (Letter | Mark | Decimal_Number | Connector_Punctuation). // If the phrase starts with a word character, and if the previous character before matched range is a word character, its matched range should be treated to not match. // If the phrase ends with a word character, and if the next character after matched range is a word character, its matched range should be treated to not match. // Please check app/javascript/mastodon/selectors/index.js and app/lib/feed_manager.rb in the Mastodon source code for more details. // // swagger:model FilterV1 type FilterV1 struct { // The contexts in which the filter should be applied. // Example: ["home","public"] // Min Items: 1 // Unique: true Context []FilterContext `json:"context"` // When the filter should no longer be applied. Null if the filter does not expire. // Example: 2024-02-01T02:57:49Z ExpiresAt string `json:"expires_at,omitempty"` // The ID of the filter in the database. ID string `json:"id,omitempty"` // Should matching entities be removed from the user's timelines/views, instead of hidden? // Example: false Irreversible bool `json:"irreversible,omitempty"` // The text to be filtered. // Example: fnord Phrase string `json:"phrase,omitempty"` // Should the filter consider word boundaries? // Example: true WholeWord bool `json:"whole_word,omitempty"` } // Validate validates this filter v1 func (m *FilterV1) Validate(formats strfmt.Registry) error { var res []error if err := m.validateContext(formats); err != nil { res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil } func (m *FilterV1) validateContext(formats strfmt.Registry) error { if swag.IsZero(m.Context) { // not required return nil } iContextSize := int64(len(m.Context)) if err := validate.MinItems("context", "body", iContextSize, 1); err != nil { return err } if err := validate.UniqueItems("context", "body", m.Context); err != nil { return err } for i := 0; i < len(m.Context); i++ { if err := m.Context[i].Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("context" + "." + strconv.Itoa(i)) } else if ce, ok := err.(*errors.CompositeError); ok { return ce.ValidateName("context" + "." + strconv.Itoa(i)) } return err } } return nil } // ContextValidate validate this filter v1 based on the context it is used func (m *FilterV1) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error if err := m.contextValidateContext(ctx, formats); err != nil { res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil } func (m *FilterV1) contextValidateContext(ctx context.Context, formats strfmt.Registry) error { for i := 0; i < len(m.Context); i++ { if swag.IsZero(m.Context[i]) { // not required return nil } if err := m.Context[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("context" + "." + strconv.Itoa(i)) } else if ce, ok := err.(*errors.CompositeError); ok { return ce.ValidateName("context" + "." + strconv.Itoa(i)) } return err } } return nil } // MarshalBinary interface implementation func (m *FilterV1) MarshalBinary() ([]byte, error) { if m == nil { return nil, nil } return swag.WriteJSON(m) } // UnmarshalBinary interface implementation func (m *FilterV1) UnmarshalBinary(b []byte) error { var res FilterV1 if err := swag.ReadJSON(b, &res); err != nil { return err } *m = res return nil }