Class: Lutaml::Xsd::SchemaLocationRule

Inherits:
ValidationRule show all
Defined in:
lib/lutaml/xsd/xsd_spec_validator.rb

Overview

Validates schemaLocation attributes

Instance Attribute Summary

Attributes inherited from ValidationRule

#version

Instance Method Summary collapse

Methods inherited from ValidationRule

#initialize

Constructor Details

This class inherits a constructor from Lutaml::Xsd::ValidationRule

Instance Method Details

#validate(repository) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/lutaml/xsd/xsd_spec_validator.rb', line 257

def validate(repository)
  errors = []
  warnings = []

  get_schemas(repository).each do |schema_file, schema|
    # Check imports
    imports = schema.respond_to?(:import) ? schema.import : []
    (imports || []).each do |import|
      next unless import.respond_to?(:namespace) && import.namespace

      warnings << "Import in #{File.basename(schema_file)} for namespace '#{import.namespace}' has no schemaLocation" if !import.respond_to?(:schema_path) || !import.schema_path || import.schema_path.empty?
    end

    # Check includes
    includes = schema.respond_to?(:include) ? schema.include : []
    (includes || []).each do |include|
      errors << "Include in #{File.basename(schema_file)} has no schemaLocation" if !include.respond_to?(:schema_path) || !include.schema_path || include.schema_path.empty?
    end
  end

  { errors: errors, warnings: warnings }
end