xsd 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +124 -0
  4. data/CHANGELOG.md +5 -0
  5. data/CODE_OF_CONDUCT.md +84 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE +21 -0
  8. data/Makefile +7 -0
  9. data/README.md +68 -0
  10. data/Rakefile +25 -0
  11. data/lib/xsd/base_object.rb +347 -0
  12. data/lib/xsd/exceptions.rb +12 -0
  13. data/lib/xsd/generator.rb +137 -0
  14. data/lib/xsd/objects/all.rb +22 -0
  15. data/lib/xsd/objects/annotation.rb +19 -0
  16. data/lib/xsd/objects/any.rb +31 -0
  17. data/lib/xsd/objects/any_attribute.rb +30 -0
  18. data/lib/xsd/objects/appinfo.rb +13 -0
  19. data/lib/xsd/objects/attribute.rb +72 -0
  20. data/lib/xsd/objects/attribute_group.rb +18 -0
  21. data/lib/xsd/objects/choice.rb +33 -0
  22. data/lib/xsd/objects/complex_content.rb +25 -0
  23. data/lib/xsd/objects/complex_type.rb +82 -0
  24. data/lib/xsd/objects/documentation.rb +18 -0
  25. data/lib/xsd/objects/element.rb +130 -0
  26. data/lib/xsd/objects/extension.rb +14 -0
  27. data/lib/xsd/objects/facet.rb +12 -0
  28. data/lib/xsd/objects/field.rb +13 -0
  29. data/lib/xsd/objects/group.rb +32 -0
  30. data/lib/xsd/objects/import.rb +67 -0
  31. data/lib/xsd/objects/key.rb +25 -0
  32. data/lib/xsd/objects/keyref.rb +33 -0
  33. data/lib/xsd/objects/list.rb +18 -0
  34. data/lib/xsd/objects/restriction.rb +49 -0
  35. data/lib/xsd/objects/schema.rb +155 -0
  36. data/lib/xsd/objects/selector.rb +15 -0
  37. data/lib/xsd/objects/sequence.rb +33 -0
  38. data/lib/xsd/objects/simple_content.rb +19 -0
  39. data/lib/xsd/objects/simple_type.rb +35 -0
  40. data/lib/xsd/objects/union.rb +23 -0
  41. data/lib/xsd/objects/unique.rb +18 -0
  42. data/lib/xsd/shared/attribute_container.rb +17 -0
  43. data/lib/xsd/shared/based.rb +37 -0
  44. data/lib/xsd/shared/complex_typed.rb +28 -0
  45. data/lib/xsd/shared/element_container.rb +12 -0
  46. data/lib/xsd/shared/min_max_occurs.rb +46 -0
  47. data/lib/xsd/shared/referenced.rb +24 -0
  48. data/lib/xsd/shared/simple_typed.rb +14 -0
  49. data/lib/xsd/validator.rb +90 -0
  50. data/lib/xsd/version.rb +5 -0
  51. data/lib/xsd/xml.rb +111 -0
  52. data/lib/xsd.rb +42 -0
  53. data/xsd.gemspec +45 -0
  54. metadata +239 -0
data/lib/xsd/xml.rb ADDED
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nokogiri'
4
+ require 'forwardable'
5
+
6
+ module XSD
7
+ class XML
8
+ extend Forwardable
9
+ include Generator
10
+ include Validator
11
+
12
+ attr_reader :options, :object_cache, :xsd
13
+
14
+ # Proxy lookup methods to schema
15
+ def_delegators :schema, :[], :elements, :all_elements, :attributes, :attribute_groups, :all_attributes,
16
+ :complex_types, :simple_types, :groups, :imports
17
+
18
+ CLASS_MAP = {
19
+ 'schema' => Schema,
20
+ 'element' => Element,
21
+ 'attribute' => Attribute,
22
+ 'choice' => Choice,
23
+ 'complexType' => ComplexType,
24
+ 'sequence' => Sequence,
25
+ 'simpleContent' => SimpleContent,
26
+ 'complexContent' => ComplexContent,
27
+ 'extension' => Extension,
28
+ 'import' => Import,
29
+ 'simpleType' => SimpleType,
30
+ 'all' => All,
31
+ 'restriction' => Restriction,
32
+ 'group' => Group,
33
+ 'any' => Any,
34
+ 'union' => Union,
35
+ 'attributeGroup' => AttributeGroup,
36
+ 'list' => List,
37
+ 'unique' => Unique,
38
+ 'selector' => Selector,
39
+ 'field' => Field,
40
+ 'annotation' => Annotation,
41
+ 'documentation' => Documentation,
42
+ 'appinfo' => Appinfo,
43
+ 'anyAttribute' => AnyAttribute,
44
+ 'key' => Key,
45
+ 'keyref' => Keyref,
46
+ # Restriction facets
47
+ 'minExclusive' => Facet,
48
+ 'minInclusive' => Facet,
49
+ 'maxExclusive' => Facet,
50
+ 'maxInclusive' => Facet,
51
+ 'totalDigits' => Facet,
52
+ 'fractionDigits' => Facet,
53
+ 'length' => Facet,
54
+ 'minLength' => Facet,
55
+ 'maxLength' => Facet,
56
+ 'enumeration' => Facet,
57
+ 'whiteSpace' => Facet,
58
+ 'pattern' => Facet
59
+ }.freeze
60
+
61
+ def initialize(xsd, **options)
62
+ # Base input validation
63
+ raise Error, 'xsd is not a Pathname nor a string' unless xsd.is_a?(Pathname) || xsd.is_a?(String)
64
+ raise Error, 'options is not a hash' unless options.is_a?(Hash)
65
+
66
+ @xsd = xsd
67
+ @options = options
68
+ @object_cache = {}
69
+ end
70
+
71
+ def logger
72
+ options[:logger] || default_logger
73
+ end
74
+
75
+ def default_logger
76
+ @default_logger ||= Logger.new($stdout).tap do |logger|
77
+ logger.level = Logger::WARN
78
+ end
79
+ end
80
+
81
+ def xml
82
+ @xsd_xml ||= xsd.is_a?(Pathname) ? File.read(xsd) : xsd
83
+ end
84
+
85
+ def imported_xsd
86
+ @imported_xsd ||= options[:imported_xsd] || {}
87
+ end
88
+
89
+ def tmp_dir
90
+ @tmp_dir ||= options[:tmp_dir]
91
+ end
92
+
93
+ def doc
94
+ @doc ||= Nokogiri::XML(xml)
95
+ end
96
+
97
+ def schema_node
98
+ raise Error, 'Document root not found, provided document does not seem to be a valid XSD' unless doc.root
99
+
100
+ doc.root.name == 'schema' ? doc.root : nil
101
+ end
102
+
103
+ def schema
104
+ @schema ||= Schema.new(self.options.merge(node: schema_node, reader: self))
105
+ end
106
+
107
+ def schema_for_namespace(_ns)
108
+ schema.schema_for_namespace(_ns)
109
+ end
110
+ end
111
+ end
data/lib/xsd.rb ADDED
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'xsd/base_object'
4
+ require 'xsd/shared/min_max_occurs'
5
+ require 'xsd/shared/referenced'
6
+ require 'xsd/shared/attribute_container'
7
+ require 'xsd/shared/element_container'
8
+ require 'xsd/shared/based'
9
+ require 'xsd/shared/simple_typed'
10
+ require 'xsd/shared/complex_typed'
11
+ require 'xsd/objects/facet'
12
+ require 'xsd/objects/attribute'
13
+ require 'xsd/objects/attribute_group'
14
+ require 'xsd/objects/sequence'
15
+ require 'xsd/objects/choice'
16
+ require 'xsd/objects/complex_type'
17
+ require 'xsd/objects/simple_content'
18
+ require 'xsd/objects/complex_content'
19
+ require 'xsd/objects/extension'
20
+ require 'xsd/objects/import'
21
+ require 'xsd/objects/restriction'
22
+ require 'xsd/objects/group'
23
+ require 'xsd/objects/all'
24
+ require 'xsd/objects/any'
25
+ require 'xsd/objects/union'
26
+ require 'xsd/objects/list'
27
+ require 'xsd/objects/unique'
28
+ require 'xsd/objects/selector'
29
+ require 'xsd/objects/field'
30
+ require 'xsd/objects/simple_type'
31
+ require 'xsd/objects/element'
32
+ require 'xsd/objects/schema'
33
+ require 'xsd/objects/annotation'
34
+ require 'xsd/objects/documentation'
35
+ require 'xsd/objects/appinfo'
36
+ require 'xsd/objects/any_attribute'
37
+ require 'xsd/objects/key'
38
+ require 'xsd/objects/keyref'
39
+ require 'xsd/generator'
40
+ require 'xsd/validator'
41
+ require 'xsd/exceptions'
42
+ require 'xsd/xml'
data/xsd.gemspec ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/xsd/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'xsd'
7
+ spec.version = XSD::VERSION
8
+ spec.authors = ['d.arkhipov']
9
+ spec.email = ['d.arkhipov@netcitylife.ru']
10
+
11
+ spec.summary = 'The Ruby XSD library is an XML Schema implementation for Ruby.'
12
+ spec.description =
13
+ 'The Ruby XSD library is an XML Schema implementation for Ruby.Provides easy and flexible access to XSD information'
14
+
15
+ spec.homepage = 'https://github.com/ekzo-dev/ruby-xsd'
16
+ spec.license = 'MIT'
17
+ spec.required_ruby_version = '>= 2.7.0'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = spec.homepage
21
+ spec.metadata['changelog_uri'] = 'https://github.com/ekzo-dev/ruby-xsd/CHANGELOG.md'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
28
+ end
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ spec.add_dependency 'builder', '~> 3.2'
35
+ spec.add_dependency 'nokogiri', '~> 1.11'
36
+ spec.add_dependency 'rake', '~> 13.0'
37
+ spec.add_dependency 'rest-client', '~> 2.1'
38
+
39
+ spec.add_development_dependency 'logger', '~> 1.5'
40
+ spec.add_development_dependency 'rspec', '~> 3.12'
41
+ spec.add_development_dependency 'rubocop', '~> 1.50'
42
+ spec.add_development_dependency 'rubocop-performance', '~> 1.17'
43
+ spec.add_development_dependency 'rubocop-rake', '~> 0.6'
44
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.10'
45
+ end
metadata ADDED
@@ -0,0 +1,239 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xsd
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - d.arkhipov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: logger
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.12'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.12'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.50'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.50'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-performance
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.17'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.17'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.6'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.6'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.10'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.10'
153
+ description: The Ruby XSD library is an XML Schema implementation for Ruby.Provides
154
+ easy and flexible access to XSD information
155
+ email:
156
+ - d.arkhipov@netcitylife.ru
157
+ executables: []
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".rspec"
162
+ - ".rubocop.yml"
163
+ - CHANGELOG.md
164
+ - CODE_OF_CONDUCT.md
165
+ - Gemfile
166
+ - LICENSE
167
+ - Makefile
168
+ - README.md
169
+ - Rakefile
170
+ - lib/xsd.rb
171
+ - lib/xsd/base_object.rb
172
+ - lib/xsd/exceptions.rb
173
+ - lib/xsd/generator.rb
174
+ - lib/xsd/objects/all.rb
175
+ - lib/xsd/objects/annotation.rb
176
+ - lib/xsd/objects/any.rb
177
+ - lib/xsd/objects/any_attribute.rb
178
+ - lib/xsd/objects/appinfo.rb
179
+ - lib/xsd/objects/attribute.rb
180
+ - lib/xsd/objects/attribute_group.rb
181
+ - lib/xsd/objects/choice.rb
182
+ - lib/xsd/objects/complex_content.rb
183
+ - lib/xsd/objects/complex_type.rb
184
+ - lib/xsd/objects/documentation.rb
185
+ - lib/xsd/objects/element.rb
186
+ - lib/xsd/objects/extension.rb
187
+ - lib/xsd/objects/facet.rb
188
+ - lib/xsd/objects/field.rb
189
+ - lib/xsd/objects/group.rb
190
+ - lib/xsd/objects/import.rb
191
+ - lib/xsd/objects/key.rb
192
+ - lib/xsd/objects/keyref.rb
193
+ - lib/xsd/objects/list.rb
194
+ - lib/xsd/objects/restriction.rb
195
+ - lib/xsd/objects/schema.rb
196
+ - lib/xsd/objects/selector.rb
197
+ - lib/xsd/objects/sequence.rb
198
+ - lib/xsd/objects/simple_content.rb
199
+ - lib/xsd/objects/simple_type.rb
200
+ - lib/xsd/objects/union.rb
201
+ - lib/xsd/objects/unique.rb
202
+ - lib/xsd/shared/attribute_container.rb
203
+ - lib/xsd/shared/based.rb
204
+ - lib/xsd/shared/complex_typed.rb
205
+ - lib/xsd/shared/element_container.rb
206
+ - lib/xsd/shared/min_max_occurs.rb
207
+ - lib/xsd/shared/referenced.rb
208
+ - lib/xsd/shared/simple_typed.rb
209
+ - lib/xsd/validator.rb
210
+ - lib/xsd/version.rb
211
+ - lib/xsd/xml.rb
212
+ - xsd.gemspec
213
+ homepage: https://github.com/ekzo-dev/ruby-xsd
214
+ licenses:
215
+ - MIT
216
+ metadata:
217
+ homepage_uri: https://github.com/ekzo-dev/ruby-xsd
218
+ source_code_uri: https://github.com/ekzo-dev/ruby-xsd
219
+ changelog_uri: https://github.com/ekzo-dev/ruby-xsd/CHANGELOG.md
220
+ post_install_message:
221
+ rdoc_options: []
222
+ require_paths:
223
+ - lib
224
+ required_ruby_version: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ version: 2.7.0
229
+ required_rubygems_version: !ruby/object:Gem::Requirement
230
+ requirements:
231
+ - - ">="
232
+ - !ruby/object:Gem::Version
233
+ version: '0'
234
+ requirements: []
235
+ rubygems_version: 3.1.6
236
+ signing_key:
237
+ specification_version: 4
238
+ summary: The Ruby XSD library is an XML Schema implementation for Ruby.
239
+ test_files: []