func()

in models/v3/schema/types/types.go [80:150]


func (d Data) Validate() error {
	if d.ResourcesContainer == 0 || d.ResourcesContainer >= ResourcesContainer(len(_ResourcesContainer_index)-1) {
		return fmt.Errorf(".ChangedAction(%d) is invalid", d.ResourcesContainer)
	}

	switch d.ResourcesContainer {
	case RCBlob:
		// We don't validate the ResourceBlobInfo here, because this gets called before
		// we upload the blob and get back the URL and size.
	case RCInline:
		if len(d.Resources) == 0 {
			return errors.New(".Resources is required when ResourcesContainer is Inline")
		}

		rscAPIVersion := ""
		var rscType [2]string
		for i, r := range d.Resources {
			if err := r.Validate(); err != nil {
				return fmt.Errorf(".Resources[%d]%w", i, err)
			}

			if r.ArmResource.arm == nil {
				return fmt.Errorf("ArmResource was not created with NewARMResource()")
			}

			// All ARMResource.Properties must be of the same type. This either gets the type on the
			// first iteration or validates that the type is the same on subsequent iterations.
			// Also makes sure that APIVersion is set on all resources if it is not set on Data and that
			// it matches if it is set on Data.
			if i == 0 {
				rscAPIVersion = r.APIVersion
				rscType[0] = r.ArmResource.arm.ResourceType.Namespace
				rscType[1] = r.ArmResource.arm.ResourceType.Type
			} else {
				compare := [2]string{
					r.ArmResource.arm.ResourceType.Namespace,
					r.ArmResource.arm.ResourceType.Type,
				}
				if unique.Make(rscType) != unique.Make(compare) {
					return errors.New("all NotificationResource.ArmResource.Properties must be of the same type")
				}
			}

			// If APIVersion is not set, it must be set on all resources.
			if d.APIVersion == "" {
				if r.APIVersion == "" {
					return errors.New("NotificationResource.APIVersion is required when not set on Data")
				}
			} else {
				// If it is set on Data, it must match on all resources or they must be empty.
				if d.APIVersion != r.APIVersion && r.APIVersion != "" {
					return errors.New("NotificationResource.APIVersion must match Data.APIVersion if set")
				}
			}

			if rscAPIVersion != r.APIVersion {
				return errors.New("all resources must have the same APIVersion")
			}

			if rscAPIVersion != "" {
				if r.ArmResource.APIVersion != rscAPIVersion {
					return errors.New("all resources must have the same APIVersion and ArmResource.APIVersion must match")
				} else if r.ArmResource.APIVersion != r.APIVersion {
					return errors.New("all resources must have the same APIVersion and ArmResource.APIVersion must match")
				}
			}
		}
	}

	return nil
}