xsd-reader 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +14 -0
- data/README.md +5 -4
- data/lib/xsd_reader/choice.rb +0 -3
- data/lib/xsd_reader/complex_content.rb +5 -0
- data/lib/xsd_reader/element.rb +2 -6
- data/lib/xsd_reader/extension.rb +8 -0
- data/lib/xsd_reader/import.rb +56 -0
- data/lib/xsd_reader/schema.rb +35 -0
- data/lib/xsd_reader/shared.rb +95 -58
- data/lib/xsd_reader/simple_type.rb +7 -0
- data/lib/xsd_reader/xml.rb +35 -2
- data/lib/xsd_reader.rb +3 -0
- data/spec/attribute_spec.rb +12 -12
- data/spec/element_spec.rb +28 -25
- data/spec/examples/ddex-v32/ddex.xsd +2116 -0
- data/spec/examples/ddex-v32/ddexC.xsd +5240 -0
- data/spec/examples/ddex-v32/ern-main.xsd +2980 -0
- data/spec/examples/ddex-v32/iso3166a2.xsd +1230 -0
- data/spec/examples/ddex-v32/iso4217a.xsd +900 -0
- data/spec/examples/ddex-v32/iso639a2.xsd +935 -0
- data/spec/examples/ddex-v36/avs.xsd +11257 -0
- data/spec/examples/{ddex-ern-v36.xsd → ddex-v36/ddex-ern-v36.xsd} +0 -0
- data/spec/extension_spec.rb +29 -0
- data/spec/import_spec.rb +48 -0
- data/spec/schema_spec.rb +63 -9
- data/spec/xml_spec.rb +7 -7
- data/spec/xsd_reader_spec.rb +172 -39
- data/xsd-reader.gemspec +2 -1
- metadata +28 -2
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe XsdReader::Extension do
|
4
|
+
let(:reader){
|
5
|
+
XsdReader::XML.new(:xsd_file => File.expand_path(File.join(File.dirname(__FILE__), 'examples', 'ddex-v32', 'ern-main.xsd')))
|
6
|
+
}
|
7
|
+
|
8
|
+
let(:element){
|
9
|
+
reader['NewReleaseMessage']['ResourceList']['SoundRecording']['SoundRecordingDetailsByTerritory']
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:extension){
|
13
|
+
element.complex_type.complex_content.extension
|
14
|
+
}
|
15
|
+
|
16
|
+
describe "#linked_complex_type" do
|
17
|
+
it "finds linked complex typesfom imported schemas" do
|
18
|
+
expect(extension.base).to eq 'ddexC:SoundRecordingDetailsByTerritory'
|
19
|
+
expect(extension.linked_complex_type.name).to eq 'SoundRecordingDetailsByTerritory'
|
20
|
+
expect(extension.linked_complex_type.schema).to be extension.schema.imports[1].reader.schema
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#ordered_elements" do
|
25
|
+
it "includes elements at the start from imported linked comlex type" do
|
26
|
+
expect(extension.ordered_elements.map(&:name)).to eq ["TerritoryCode", "ExcludedTerritoryCode", "Title", "DisplayArtist", "ResourceContributor", "IndirectResourceContributor", "RightsAgreementId", "LabelName", "RightsController", "RemasteredDate", "OriginalResourceReleaseDate", "PLine", "CourtesyLine", "SequenceNumber", "HostSoundCarrier", "MarketingComment", "Genre", "ParentalWarningType", "AvRating", "TechnicalSoundRecordingDetails", "FulfillmentDate", "Keywords", "Synopsis"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end # describe XsdReader::Extension
|
data/spec/import_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe XsdReader::Import do
|
4
|
+
let(:reader){
|
5
|
+
XsdReader::XML.new(:xsd_file => File.expand_path(File.join(File.dirname(__FILE__), 'examples', 'ddex-v36', 'ddex-ern-v36.xsd')))
|
6
|
+
}
|
7
|
+
|
8
|
+
let(:import){
|
9
|
+
reader.imports[0]
|
10
|
+
}
|
11
|
+
|
12
|
+
it "gives the namespace" do
|
13
|
+
expect(import.namespace).to eq 'http://ddex.net/xml/avs/avs'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "gives the schema location" do
|
17
|
+
expect(import.schema_location).to eq 'avs.xsd'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "gives a download uri" do
|
21
|
+
expect(import.uri).to eq 'http://ddex.net/xml/avs/avs.xsd'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "gives a reader for the external XSD" do
|
25
|
+
expect(import.reader.class).to eq XsdReader::XML
|
26
|
+
end
|
27
|
+
|
28
|
+
it "gives a download_path to save the imported xsd file to, if an xsd_file options is provided, containing the path to the parent xsd" do
|
29
|
+
expect(import.options[:xsd_file]).to eq reader.options[:xsd_file]
|
30
|
+
expect(import.download_path).to eq File.expand_path(File.join(File.dirname(__FILE__), 'examples', 'ddex-v36', 'avs.xsd'))
|
31
|
+
end
|
32
|
+
|
33
|
+
it "downloads related xsd files" do
|
34
|
+
r1 = XsdReader::XML.new(:xsd_file => File.expand_path(File.join(File.dirname(__FILE__), 'examples', 'ddex-v36', 'avs.xsd')))
|
35
|
+
r2 = import.reader
|
36
|
+
expect(r1.elements.map(&:name)).to eq r2.elements.map(&:name)
|
37
|
+
expect(r1.simple_types.map(&:name)).to eq r2.simple_types.map(&:name)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "automatically saves related xsd content" do
|
41
|
+
skip 'downloading test disabled for efficiency'
|
42
|
+
FileUtils.rm(import.download_path) if File.exist?(import.download_path)
|
43
|
+
# To get the reaed, the import object has to download the XSD data first,
|
44
|
+
# which is automatically saved locally
|
45
|
+
expect(import.reader.options[:xsd_file]).to eq File.expand_path(File.join(File.dirname(__FILE__), 'examples', 'avs.xsd'))
|
46
|
+
expect(File.file?(import.download_path)).to eq true
|
47
|
+
end
|
48
|
+
end # describe XsdReader::Import
|
data/spec/schema_spec.rb
CHANGED
@@ -1,17 +1,71 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
describe XsdReader do
|
4
|
-
|
5
|
-
|
3
|
+
describe XsdReader::Schema do
|
4
|
+
let(:reader){
|
5
|
+
XsdReader::XML.new(:xsd_file => File.expand_path(File.join(File.dirname(__FILE__), 'examples', 'ddex-v36', 'ddex-ern-v36.xsd')))
|
6
|
+
}
|
7
|
+
|
8
|
+
let(:schema){
|
9
|
+
reader.schema
|
10
|
+
}
|
11
|
+
|
12
|
+
describe "#elements" do
|
13
|
+
it "gives a element readers" do
|
14
|
+
expect(schema.elements.map(&:class)).to eq [XsdReader::Element]*2
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#target_namespace' do
|
19
|
+
it "gives the target namespace" do
|
20
|
+
expect(schema.target_namespace).to eq 'http://ddex.net/xml/ern/36'
|
21
|
+
end
|
6
22
|
end
|
7
23
|
|
8
|
-
describe
|
9
|
-
|
10
|
-
|
24
|
+
describe '#namespaces' do
|
25
|
+
it 'returns a hash of namespace shortcuts' do
|
26
|
+
expect(schema.namespaces).to eq({
|
27
|
+
'xmlns:xs' => "http://www.w3.org/2001/XMLSchema",
|
28
|
+
'xmlns:ern' => "http://ddex.net/xml/ern/36",
|
29
|
+
'xmlns:avs' => "http://ddex.net/xml/avs/avs"
|
30
|
+
})
|
11
31
|
end
|
32
|
+
end
|
12
33
|
|
13
|
-
|
14
|
-
|
34
|
+
describe "#import_by_namespace" do
|
35
|
+
it "returns import objects for the given namespace" do
|
36
|
+
import = schema.import_by_namespace('http://ddex.net/xml/avs/avs')
|
37
|
+
expect(import.class).to eq XsdReader::Import
|
38
|
+
expect(import.namespace).to eq 'http://ddex.net/xml/avs/avs'
|
39
|
+
expect(import.reader.schema.target_namespace).to eq 'http://ddex.net/xml/avs/avs'
|
40
|
+
expect(import).to be schema.imports[0]
|
15
41
|
end
|
42
|
+
|
43
|
+
it "returns import objects for given namespace codes" do
|
44
|
+
import = schema.import_by_namespace('avs')
|
45
|
+
expect(import.class).to eq XsdReader::Import
|
46
|
+
expect(import.namespace).to eq 'http://ddex.net/xml/avs/avs'
|
47
|
+
expect(import.reader.schema.target_namespace).to eq 'http://ddex.net/xml/avs/avs'
|
48
|
+
expect(import).to be schema.imports[0]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns import objects for given namespace codes with xmlns prefix" do
|
52
|
+
import = schema.import_by_namespace('xmlns:avs')
|
53
|
+
expect(import.class).to eq XsdReader::Import
|
54
|
+
expect(import.namespace).to eq 'http://ddex.net/xml/avs/avs'
|
55
|
+
expect(import.reader.schema.target_namespace).to eq 'http://ddex.net/xml/avs/avs'
|
56
|
+
expect(import).to be schema.imports[0]
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns nil when no matching import is found" do
|
60
|
+
expect(schema.import_by_namespace('foo')).to eq nil
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns nil when a nil namespace is given" do
|
64
|
+
expect(schema.import_by_namespace(nil)).to eq nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "includes imported definitions as if they were local" do
|
69
|
+
expect(schema.simple_types.map(&:name)).to eq ["ddex_LocalCollectionAnchorReference", "ddex_LocalResourceAnchorReference", "AccessLimitation", "AdministratingRecordCompanyRole", "AllTerritoryCode", "ArtistRole", "AudioCodecType", "BinaryDataType", "BusinessContributorRole", "CalculationType", "CarrierType", "CdProtectionType", "CharacterType", "CodingType", "CollectionType", "CommercialModelType", "CompilationType", "ContainerFormat", "CreationType", "CreativeContributorRole", "CueOrigin", "CueSheetType", "CueUseType", "CurrencyCode", "CurrentTerritoryCode", "DataMismatchResponseType", "DataMismatchStatus", "DataMismatchType", "DdexTerritoryCode", "DeductionRateType", "DeliveryActionType", "DeliveryMessageType", "DeprecatedCurrencyCode", "DeprecatedIsoTerritoryCode", "DigitizationMode", "DisputeReason", "DistributionChannelType", "DpidStatus", "DrmEnforcementType", "DrmPlatformType", "DsrMessageType", "EquipmentType", "ErnMessageType", "ErncFileStatus", "ErncProposedActionType", "ExpressionType", "ExternallyLinkedResourceType", "FileStatus", "FingerprintAlgorithmType", "GoverningAgreementType", "HashSumAlgorithmType", "ImageCodecType", "ImageType", "InvoiceAvailabilityStatus", "IsoCurrencyCode", "IsoLanguageCode", "IsoTerritoryCode", "LabelNameType", "LicenseOrClaimRefusalReason", "LicenseOrClaimRequestUpdateReason", "LicenseOrClaimUpdateReason", "LicenseRejectionReason", "LicenseStatus", "LicensingProcessStatus", "LodFileStatus", "LodProposedActionType", "MembershipType", "MessageActionType", "MessageContentRevenueType", "MessageContextType", "MessageControlType", "MidiType", "MlcMessageType", "MusicalWorkContributorRole", "MusicalWorkRightsClaimType", "MusicalWorkType", "MwlCaCMessageInBatchType", "MwnMessageType", "NewReleaseMessageStatus", "OperatingSystemType", "OrderType", "PLineType", "ParentalWarningType", "PartyRelationshipType", "PercentageType", "PriceInformationType", "PriceRangeType", "PriceType", "Priority", "ProductType", "ProjectContributorRelationshipType", "Purpose", "RateModificationType", "RatingAgency", "ReasonType", "RecipientRevenueType", "RecordingMode", "RedeliveryReasonType", "ReferenceUnit", "RelationalRelator", "ReleaseAvailabilityStatus", "ReleaseRelationshipType", "ReleaseResourceType", "ReleaseType", "ReportFormat", "ReportType", "RequestReason", "RequestedActionType", "ResourceContributorRole", "ResourceOmissionReason", "ResourceType", "RevenueSourceType", "RightShareRelationshipType", "RightShareType", "RightsClaimPolicyType", "RightsControllerRole", "RightsControllerType", "RightsCoverage", "RoyaltyRateCalculationType", "RoyaltyRateType", "SalesReportAvailabilityStatus", "Sex", "SheetMusicCodecType", "SheetMusicType", "SoftwareType", "SoundProcessorType", "SoundRecordingType", "SupplyChainStatus", "TaxScope", "TaxType", "TerritoryCodeType", "TerritoryCodeTypeIncludingDeprecatedCodes", "TextCodecType", "TextType", "ThemeType", "TisTerritoryCode", "TitleType", "TrackContributorRelationshipType", "UnitOfBitRate", "UnitOfConditionValue", "UnitOfExtent", "UnitOfFrameRate", "UnitOfFrequency", "UpdateIndicator", "UseType", "UserInterfaceType", "ValueType", "VideoCodecType", "VideoContentType", "VideoDefinitionType", "VideoType", "VisualPerceptionType", "VocalType", "WsMessageStatus", "TerritoryCode"]
|
16
70
|
end
|
17
|
-
end # describe XsdReader
|
71
|
+
end # describe XsdReader::Schema
|
data/spec/xml_spec.rb
CHANGED
@@ -2,22 +2,22 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
|
3
3
|
describe XsdReader do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
let(:reader){
|
6
|
+
XsdReader::XML.new(:xsd_file => File.expand_path(File.join(File.dirname(__FILE__), 'examples', 'ddex-v36', 'ddex-ern-v36.xsd')))
|
7
|
+
}
|
8
8
|
|
9
9
|
describe XsdReader::XML do
|
10
10
|
it "gives a schema_node" do
|
11
|
-
expect(
|
12
|
-
expect(
|
11
|
+
expect(reader.schema_node.name).to eq 'schema'
|
12
|
+
expect(reader.schema_node.namespaces).to eq({"xmlns:xs"=>"http://www.w3.org/2001/XMLSchema", "xmlns:ern"=>"http://ddex.net/xml/ern/36", "xmlns:avs"=>"http://ddex.net/xml/avs/avs"})
|
13
13
|
end
|
14
14
|
|
15
15
|
it "gives a schema reader" do
|
16
|
-
expect(
|
16
|
+
expect(reader.schema.class).to eq XsdReader::Schema
|
17
17
|
end
|
18
18
|
|
19
19
|
it "gives an elements shortcut to its schema's shortcuts" do
|
20
|
-
expect(
|
20
|
+
expect(reader.elements.map(&:name)).to eq reader.schema.elements.map(&:name)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
data/spec/xsd_reader_spec.rb
CHANGED
@@ -1,62 +1,195 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
describe XsdReader do
|
4
|
+
let(:logger){
|
5
|
+
logger = Logger.new(STDOUT)
|
6
|
+
logger.level = Logger::DEBUG
|
7
|
+
logger
|
8
|
+
}
|
4
9
|
|
5
|
-
|
6
|
-
|
10
|
+
let(:reader){
|
11
|
+
XsdReader::XML.new(:xsd_file => File.expand_path(File.join(File.dirname(__FILE__), 'examples', 'ddex-v36', 'ddex-ern-v36.xsd')), :logger => logger)
|
12
|
+
}
|
13
|
+
|
14
|
+
let(:v32){
|
15
|
+
XsdReader::XML.new(:xsd_file => File.expand_path(File.join(File.dirname(__FILE__), 'examples', 'ddex-v32', 'ern-main.xsd')))
|
16
|
+
}
|
17
|
+
|
18
|
+
# do caching tests first, so they can show the initial -cacheless- situation
|
19
|
+
describe 'caching' do
|
20
|
+
it 'start with caches empty' do
|
21
|
+
cache_names = [:direct_elements, :attributes, :all_elements, :sequences, :choices, :complex_types, :linked_complex_type, :simple_contents, :extensions]
|
22
|
+
expect(cache_names.map{|name| "#{name}: #{reader.instance_variable_get("@#{name}").inspect}"}).to eq cache_names.map{|name| "#{name}: #{nil.inspect}"}
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'caches some relationships to improve performance' do
|
26
|
+
expect(reader.instance_variable_get('@schema')).to eq nil
|
27
|
+
expect(reader.instance_variable_get('@elements')).to eq nil
|
28
|
+
# the next line causes new caches to be created
|
29
|
+
expect(reader['NewReleaseMessage'].instance_variable_get('@all_elements')).to eq nil
|
30
|
+
expect(reader.instance_variable_get('@schema').class).to eq XsdReader::Schema
|
31
|
+
expect(reader.schema.instance_variable_get('@direct_elements').length).to eq 2
|
32
|
+
# the next line causes new caches to be created
|
33
|
+
expect(reader['NewReleaseMessage']['NewReleaseMessage'].instance_variable_get('@all_elements')).to eq nil
|
34
|
+
expect(reader['NewReleaseMessage'].instance_variable_get('@all_elements').first.name).to eq 'MessageHeader'
|
35
|
+
# etc.
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#elements" do
|
40
|
+
it "gives all child element definitions" do
|
41
|
+
expect(reader.elements.map(&:name)).to eq ['NewReleaseMessage', 'CatalogListMessage']
|
42
|
+
expect(reader.elements[0].elements[0].name).to eq 'MessageHeader'
|
43
|
+
end
|
7
44
|
end
|
8
45
|
|
9
|
-
|
10
|
-
|
11
|
-
|
46
|
+
describe "#all_elements" do
|
47
|
+
it "includes elements from linked complex types fmor an imported schema" do
|
48
|
+
el = v32['NewReleaseMessage']['CollectionList']['Collection']['Title']
|
49
|
+
expect(el.all_elements.map(&:name)).to eq ['TitleText', 'SubTitle']
|
50
|
+
end
|
51
|
+
|
52
|
+
it "includes elements from extensions in linked complex types" do
|
53
|
+
el = v32['NewReleaseMessage']['ResourceList']['SoundRecording']['SoundRecordingDetailsByTerritory']
|
54
|
+
expect(el.elements.map(&:name)).to eq ["TerritoryCode", "ExcludedTerritoryCode", "Title", "DisplayArtist", "ResourceContributor", "IndirectResourceContributor", "RightsAgreementId", "LabelName", "RightsController", "RemasteredDate", "OriginalResourceReleaseDate", "PLine", "CourtesyLine", "SequenceNumber", "HostSoundCarrier", "MarketingComment", "Genre", "ParentalWarningType", "AvRating", "TechnicalSoundRecordingDetails", "FulfillmentDate", "Keywords", "Synopsis"]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "[] operator" do
|
59
|
+
it "gives a child element object (matching by name)" do
|
60
|
+
expect(reader['NewReleaseMessage'].name).to eq 'NewReleaseMessage'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "supports linking" do
|
64
|
+
# this supports linking:
|
65
|
+
expect(reader['NewReleaseMessage']['ReleaseList']['Release'].attributes.map(&:name)).to eq ["LanguageAndScriptCode", "IsMainRelease"]
|
66
|
+
end
|
67
|
+
|
68
|
+
it "gives a specific element in the hierarchy when passing an array argument" do
|
69
|
+
expect(reader[['NewReleaseMessage', 'ResourceList', 'SoundRecording']].name).to eq 'SoundRecording'
|
70
|
+
expect(reader[['NewReleaseMessage', 'ResourceList', 'SoundRecording']].multiple_allowed?).to eq true
|
71
|
+
end
|
72
|
+
|
73
|
+
it "automatically turns symbol arguments into strings" do
|
74
|
+
expect(reader[:NewReleaseMessage].name).to eq 'NewReleaseMessage'
|
75
|
+
# this supports linking:
|
76
|
+
expect(reader[:NewReleaseMessage]['ReleaseList'][:Release].attributes.map(&:name)).to eq ["LanguageAndScriptCode", "IsMainRelease"]
|
77
|
+
expect(reader[:NewReleaseMessage, 'ReleaseList', :Release].attributes.map(&:name)).to eq ["LanguageAndScriptCode", "IsMainRelease"]
|
78
|
+
end
|
79
|
+
|
80
|
+
it "return nil and doesn't raise an exceptions when getting invalid input" do
|
81
|
+
expect{
|
82
|
+
expect(reader[:NewReleaseMessage, 'Nothing', '@Whatever', 'Foo']).to eq nil
|
83
|
+
}.to_not raise_error
|
84
|
+
end
|
12
85
|
end
|
13
86
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
87
|
+
describe "#child_elements?" do
|
88
|
+
it "returns wether an element has child element definitions or not" do
|
89
|
+
expect(reader['NewReleaseMessage'].child_elements?).to eq true
|
90
|
+
expect(reader['NewReleaseMessage']['MessageHeader']['MessageThreadId'].child_elements?).to eq false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#min_occurs" do
|
95
|
+
it "gives the minOccurs attribute as an integer" do
|
96
|
+
expect(reader['NewReleaseMessage']['ResourceList']['SoundRecording'].min_occurs).to eq 0
|
97
|
+
end
|
98
|
+
|
99
|
+
it "returns nil when an element has no minOccurs attribute specified" do
|
100
|
+
expect(reader['NewReleaseMessage']['ResourceList'].min_occurs).to eq nil
|
101
|
+
end
|
18
102
|
end
|
19
103
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
104
|
+
describe "#max_occurs" do
|
105
|
+
it "returns the :unbounded symbol when there's no limit to the number of occurences of an element" do
|
106
|
+
expect(reader['NewReleaseMessage']['ResourceList']['SoundRecording'].max_occurs).to eq :unbounded
|
107
|
+
end
|
24
108
|
end
|
25
109
|
|
26
|
-
|
27
|
-
|
28
|
-
|
110
|
+
describe "#multiple_allowed?" do
|
111
|
+
it "indicates if multiple instances of an element are allowed" do
|
112
|
+
expect(reader['NewReleaseMessage']['ResourceList'].multiple_allowed?).to be false
|
113
|
+
expect(reader['NewReleaseMessage']['ResourceList']['SoundRecording'].multiple_allowed?).to be true
|
114
|
+
end
|
29
115
|
end
|
30
116
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
117
|
+
describe "#required?" do
|
118
|
+
it "indicates if an element is required" do
|
119
|
+
expect(reader['NewReleaseMessage'].required?).to be true
|
120
|
+
expect(reader['NewReleaseMessage']['ResourceList'].required?).to be true
|
121
|
+
expect(reader['NewReleaseMessage']['CollectionList'].required?).to be false
|
122
|
+
end
|
123
|
+
|
124
|
+
it "indicates if an attribute is required" do
|
125
|
+
expect(reader['NewReleaseMessage']['@MessageSchemaVersionId'].required?).to eq true
|
126
|
+
expect(reader['NewReleaseMessage']['@LanguageAndScriptCode'].required?).to eq false
|
127
|
+
end
|
35
128
|
end
|
36
129
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
130
|
+
describe "#optional?" do
|
131
|
+
it "indicates if an element is optonal (opposite of required)" do
|
132
|
+
expect(reader['NewReleaseMessage'].optional?).to be false
|
133
|
+
expect(reader['NewReleaseMessage']['ResourceList'].optional?).to be false
|
134
|
+
expect(reader['NewReleaseMessage']['CollectionList'].optional?).to be true
|
135
|
+
end
|
41
136
|
end
|
42
137
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
138
|
+
describe "imports" do
|
139
|
+
it "finds imported types for elements" do
|
140
|
+
simple_type = reader['NewReleaseMessage']['DealList']['ReleaseDeal']['Deal']['DealTerms']['WebPolicy']['AccessLimitation'].linked_simple_type
|
141
|
+
expect(simple_type.class).to eq XsdReader::SimpleType
|
142
|
+
expect(simple_type.name).to eq 'AccessLimitation'
|
143
|
+
# byebug
|
144
|
+
expect(simple_type.schema).to be reader.imports[0].reader.schema
|
145
|
+
end
|
47
146
|
end
|
48
147
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
148
|
+
describe "#schema_for_namespace" do
|
149
|
+
let(:v32){
|
150
|
+
XsdReader::XML.new(:xsd_file => File.expand_path(File.join(File.dirname(__FILE__), 'examples', 'ddex-v32', 'ern-main.xsd')))
|
151
|
+
}
|
152
|
+
|
153
|
+
it "returns the schema object for a specified namespace" do
|
154
|
+
expect(v32.schema_for_namespace('http://ddex.net/xml/2010/ern-main/32').target_namespace).to eq 'http://ddex.net/xml/2010/ern-main/32'
|
155
|
+
expect(v32.schema_for_namespace('http://ddex.net/xml/2010/ern-main/32')).to be v32.schema
|
156
|
+
expect(v32.schema.schema_for_namespace('http://ddex.net/xml/2010/ern-main/32')).to be v32.schema
|
157
|
+
expect(v32['NewReleaseMessage'].schema_for_namespace('http://ddex.net/xml/2010/ern-main/32')).to be v32.schema
|
158
|
+
end
|
159
|
+
|
160
|
+
it "returns the schema object for a specified namespace code" do
|
161
|
+
expect(v32.schema_for_namespace('ernm').target_namespace).to eq 'http://ddex.net/xml/2010/ern-main/32'
|
162
|
+
expect(v32.schema_for_namespace('ernm')).to be v32.schema
|
163
|
+
expect(v32.schema.schema_for_namespace('ernm')).to be v32.schema
|
164
|
+
expect(v32['NewReleaseMessage']['ResourceList'].schema_for_namespace('ernm')).to be v32.schema
|
165
|
+
end
|
166
|
+
|
167
|
+
it "finds imported schemas" do
|
168
|
+
expect(v32.schema_for_namespace('http://ddex.net/xml/20100712/ddexC').target_namespace).to eq 'http://ddex.net/xml/20100712/ddexC'
|
169
|
+
expect(v32.schema_for_namespace('http://ddex.net/xml/20100712/ddexC')).to be v32.imports[1].reader.schema
|
170
|
+
expect(v32.schema.schema_for_namespace('ddex').target_namespace).to eq 'http://ddex.net/xml/20100712/ddex'
|
171
|
+
expect(v32.schema.schema_for_namespace('ddex')).to be v32.imports[0].reader.schema
|
172
|
+
expect(v32.schema_for_namespace('ddexC').target_namespace).to eq 'http://ddex.net/xml/20100712/ddexC'
|
173
|
+
expect(v32.schema_for_namespace('ddexC')).to be v32.imports[1].reader.schema
|
174
|
+
end
|
53
175
|
end
|
54
176
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
177
|
+
describe "#linked_complex_type" do
|
178
|
+
it "finds complex types for elements within the same schema" do
|
179
|
+
el = reader['NewReleaseMessage']['MessageHeader']
|
180
|
+
ct = el.linked_complex_type
|
181
|
+
expect(ct.class).to eq XsdReader::ComplexType
|
182
|
+
expect(ct.name).to eq 'MessageHeader'
|
183
|
+
expect(ct.schema).to be el.schema
|
184
|
+
end
|
185
|
+
|
186
|
+
it "finds complex types for elements on imported schemas based on namespace prefix" do
|
187
|
+
el = v32['NewReleaseMessage']['CollectionList']['Collection']['Title']
|
188
|
+
ct = el.linked_complex_type
|
189
|
+
expect(ct.class).to eq XsdReader::ComplexType
|
190
|
+
expect(ct.name).to eq 'Title'
|
191
|
+
expect(ct.schema).to be el.schema.imports[1].reader.schema
|
192
|
+
expect(el.complex_type).to be ct
|
193
|
+
end
|
194
|
+
end
|
62
195
|
end
|
data/xsd-reader.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
GEM_NAME="xsd-reader"
|
2
|
-
PKG_VERSION='0.0
|
2
|
+
PKG_VERSION='0.1.0'
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = GEM_NAME
|
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
9
9
|
|
10
10
|
s.add_dependency 'nokogiri'
|
11
|
+
s.add_dependency 'rest-client'
|
11
12
|
s.add_development_dependency 'rspec'
|
12
13
|
|
13
14
|
s.author = "Mark van de Korput"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xsd-reader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark van de Korput
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,17 +67,29 @@ files:
|
|
53
67
|
- lib/xsd_reader.rb
|
54
68
|
- lib/xsd_reader/attribute.rb
|
55
69
|
- lib/xsd_reader/choice.rb
|
70
|
+
- lib/xsd_reader/complex_content.rb
|
56
71
|
- lib/xsd_reader/complex_type.rb
|
57
72
|
- lib/xsd_reader/element.rb
|
58
73
|
- lib/xsd_reader/extension.rb
|
74
|
+
- lib/xsd_reader/import.rb
|
59
75
|
- lib/xsd_reader/schema.rb
|
60
76
|
- lib/xsd_reader/sequence.rb
|
61
77
|
- lib/xsd_reader/shared.rb
|
62
78
|
- lib/xsd_reader/simple_content.rb
|
79
|
+
- lib/xsd_reader/simple_type.rb
|
63
80
|
- lib/xsd_reader/xml.rb
|
64
81
|
- spec/attribute_spec.rb
|
65
82
|
- spec/element_spec.rb
|
66
|
-
- spec/examples/ddex-
|
83
|
+
- spec/examples/ddex-v32/ddex.xsd
|
84
|
+
- spec/examples/ddex-v32/ddexC.xsd
|
85
|
+
- spec/examples/ddex-v32/ern-main.xsd
|
86
|
+
- spec/examples/ddex-v32/iso3166a2.xsd
|
87
|
+
- spec/examples/ddex-v32/iso4217a.xsd
|
88
|
+
- spec/examples/ddex-v32/iso639a2.xsd
|
89
|
+
- spec/examples/ddex-v36/avs.xsd
|
90
|
+
- spec/examples/ddex-v36/ddex-ern-v36.xsd
|
91
|
+
- spec/extension_spec.rb
|
92
|
+
- spec/import_spec.rb
|
67
93
|
- spec/schema_spec.rb
|
68
94
|
- spec/spec_helper.rb
|
69
95
|
- spec/xml_spec.rb
|