func()

in code/go/internal/yamlschema/loader.go [48:79]


func (s *FileSchema) Validate(fsys fs.FS, filePath string) specerrors.ValidationErrors {
	data, err := loadItemSchema(fsys, filePath, s.options.ContentType, s.options.SpecVersion)
	if err != nil {
		return specerrors.ValidationErrors{specerrors.NewStructuredError(err, specerrors.UnassignedCode)}
	}

	formatCheckersMutex.Lock()
	defer func() {
		unloadRelativePathFormatChecker()
		unloadDataStreamNameFormatChecker()
		formatCheckersMutex.Unlock()
	}()

	loadRelativePathFormatChecker(fsys, path.Dir(filePath), s.options.Limits.MaxRelativePathSize())
	loadDataStreamNameFormatChecker(fsys, path.Dir(filePath))
	result, err := s.schema.Validate(gojsonschema.NewBytesLoader(data))
	if err != nil {
		return specerrors.ValidationErrors{specerrors.NewStructuredError(err, specerrors.UnassignedCode)}
	}

	if !result.Valid() {
		var errs specerrors.ValidationErrors
		for _, re := range result.Errors() {
			errs = append(errs,
				specerrors.NewStructuredErrorf("field %s: %s", re.Field(), adjustErrorDescription(re.Description())),
			)
		}
		return errs
	}

	return nil // item content is valid according to the loaded schema
}