Class: Lutaml::Xsd::DuplicateDefinitionRule
- Inherits:
-
ValidationRule
- Object
- ValidationRule
- Lutaml::Xsd::DuplicateDefinitionRule
- Defined in:
- lib/lutaml/xsd/xsd_spec_validator.rb
Overview
Validates for duplicate type/element/attribute definitions
Instance Attribute Summary
Attributes inherited from ValidationRule
Instance Method Summary collapse
Methods inherited from ValidationRule
Constructor Details
This class inherits a constructor from Lutaml::Xsd::ValidationRule
Instance Method Details
#validate(repository) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/lutaml/xsd/xsd_spec_validator.rb', line 192 def validate(repository) errors = [] warnings = [] # Track definitions by namespace and name definitions = {} get_schemas(repository).each do |schema_file, schema| namespace = schema.target_namespace || "(no namespace)" # Check complex types (schema.complex_type || []).each do |type| next unless type.name key = "#{namespace}::complexType::#{type.name}" if definitions[key] errors << "Duplicate complexType '#{type.name}' in namespace '#{namespace}' (#{File.basename(schema_file)} and #{File.basename(definitions[key])})" else definitions[key] = schema_file end end # Check simple types (schema.simple_type || []).each do |type| next unless type.name key = "#{namespace}::simpleType::#{type.name}" if definitions[key] errors << "Duplicate simpleType '#{type.name}' in namespace '#{namespace}' (#{File.basename(schema_file)} and #{File.basename(definitions[key])})" else definitions[key] = schema_file end end # Check elements (schema.element || []).each do |elem| next unless elem.name key = "#{namespace}::element::#{elem.name}" if definitions[key] errors << "Duplicate element '#{elem.name}' in namespace '#{namespace}' (#{File.basename(schema_file)} and #{File.basename(definitions[key])})" else definitions[key] = schema_file end end # Check attributes (schema.attribute || []).each do |attr| next unless attr.name key = "#{namespace}::attribute::#{attr.name}" if definitions[key] errors << "Duplicate attribute '#{attr.name}' in namespace '#{namespace}' (#{File.basename(schema_file)} and #{File.basename(definitions[key])})" else definitions[key] = schema_file end end end { errors: errors, warnings: warnings } end |