oas_parser 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 595ef67c6f390240ee6a98aac6bf63c2b954df09
4
- data.tar.gz: 11d86af03188e0bc04ff6b1f1bbe6dd4aa90243a
3
+ metadata.gz: 9110cf5aa4a2d8a2a48ddd895fa6f022f3b58dd1
4
+ data.tar.gz: 70e5357430309ed3d4317de5a7a79e109ea045bd
5
5
  SHA512:
6
- metadata.gz: 9f0aad769f5924b21a6784cfe9f117a1308da56c3d4b7fdf95c1b818d4c26d15e9af7f040132fb1a9cafd4f0016e07847be271436c071021b170d2df7af7326e
7
- data.tar.gz: a0eac06844d4d403e16005f088c1d71154cf48a8393537eb85c6aeff2331b29cab2cd93029fbf16c300b2015759e1c7fd875fa316d9a51fcb0ec8aefc1b49b83
6
+ metadata.gz: 6f78415f5deb0af71f6f3e05074e5f239ebe5c31fef5ff25a2f4a593e802f719d4e4d49f7fccc9aa8d59e456bad7ede1eba213f561225d784f7c7b23b5e28240
7
+ data.tar.gz: d3e9334eafd9039a9c1fb356c561b3185d465217ba56a78a3ce55e0951e567d1a6c821bce62feb88d4fa4b3fd4d12a287c72a4c9e730c7bd9ad166d5d91d75cb
data/Gemfile.lock CHANGED
@@ -1,27 +1,37 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oas_parser (0.1.0)
4
+ oas_parser (0.2.0)
5
+ activesupport (~> 5.1.2)
5
6
  addressable (~> 2.3)
7
+ builder (~> 3.2.3)
6
8
  deep_merge (~> 1.2.1)
7
9
  guard-rspec (~> 4.7.3)
8
10
  json_schema (~> 0.15.0)
11
+ nokogiri (~> 1.8.1)
9
12
 
10
13
  GEM
11
14
  remote: https://rubygems.org/
12
15
  specs:
16
+ activesupport (5.1.4)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (~> 0.7)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
13
21
  addressable (2.5.2)
14
22
  public_suffix (>= 2.0.2, < 4.0)
23
+ builder (3.2.3)
15
24
  coderay (1.1.2)
25
+ concurrent-ruby (1.0.5)
16
26
  deep_merge (1.2.1)
17
27
  diff-lcs (1.3)
18
28
  docile (1.1.5)
19
29
  ffi (1.9.18)
20
30
  formatador (0.2.5)
21
- guard (2.14.1)
31
+ guard (2.14.2)
22
32
  formatador (>= 0.2.4)
23
33
  listen (>= 2.7, < 4.0)
24
- lumberjack (~> 1.0)
34
+ lumberjack (>= 1.0.12, < 2.0)
25
35
  nenv (~> 0.1)
26
36
  notiffany (~> 0.0)
27
37
  pry (>= 0.9.12)
@@ -32,6 +42,8 @@ GEM
32
42
  guard (~> 2.1)
33
43
  guard-compat (~> 1.1)
34
44
  rspec (>= 2.99.0, < 4.0)
45
+ i18n (0.9.3)
46
+ concurrent-ruby (~> 1.0)
35
47
  json (2.1.0)
36
48
  json_schema (0.15.0)
37
49
  listen (3.1.5)
@@ -40,7 +52,11 @@ GEM
40
52
  ruby_dep (~> 1.2)
41
53
  lumberjack (1.0.12)
42
54
  method_source (0.9.0)
55
+ mini_portile2 (2.3.0)
56
+ minitest (5.11.1)
43
57
  nenv (0.3.0)
58
+ nokogiri (1.8.1)
59
+ mini_portile2 (~> 2.3.0)
44
60
  notiffany (0.1.1)
45
61
  nenv (~> 0.1)
46
62
  shellany (~> 0.0)
@@ -73,6 +89,9 @@ GEM
73
89
  simplecov-html (~> 0.10.0)
74
90
  simplecov-html (0.10.2)
75
91
  thor (0.20.0)
92
+ thread_safe (0.3.6)
93
+ tzinfo (1.2.4)
94
+ thread_safe (~> 0.1)
76
95
 
77
96
  PLATFORMS
78
97
  ruby
@@ -6,12 +6,44 @@ module OasParser
6
6
  @raw = raw
7
7
  end
8
8
 
9
- def parse
9
+ def parse(mode = nil)
10
+ @mode = mode
10
11
  route(@raw)
11
12
  end
12
13
 
14
+ def json
15
+ parse('json').to_json
16
+ end
17
+
18
+ def xml(xml_options = {})
19
+ xml_options ||= {}
20
+ xml_options = default_xml_options.merge(xml_options)
21
+
22
+ raw_xml = parse('xml').to_xml(xml_options)
23
+
24
+ xml_document = Nokogiri::XML(raw_xml)
25
+
26
+ xml_document.xpath('//__attributes').each do |attributes|
27
+ attributes.children.each do |attribute|
28
+ next unless attribute.class == Nokogiri::XML::Element
29
+ attribute.parent.parent.css("> #{attribute.name}").remove
30
+ attribute.parent.parent[attribute.name] = attribute.content
31
+ end
32
+ end
33
+
34
+ xml_document.xpath('//__attributes').each(&:remove)
35
+
36
+ xml_document.to_xml.each_line.reject { |x| x.strip == '' }.join
37
+ end
38
+
13
39
  private
14
40
 
41
+ def default_xml_options
42
+ {
43
+ dasherize: false
44
+ }
45
+ end
46
+
15
47
  def route(root_object)
16
48
  case root_object['type']
17
49
  when 'object'
@@ -43,6 +75,11 @@ module OasParser
43
75
  elsif object['properties']
44
76
  o = {}
45
77
  object['properties'].each do |key, value|
78
+ if @mode == 'xml' && is_xml_attribute?(value)
79
+ o['__attributes'] ||= {}
80
+ o['__attributes'][key] = parameter_value(value)
81
+ end
82
+
46
83
  o[key] = parameter_value(value)
47
84
  end
48
85
 
@@ -99,5 +136,14 @@ module OasParser
99
136
  return true if object['properties']
100
137
  false
101
138
  end
139
+
140
+ def has_xml_options?(object)
141
+ object['xml'].present?
142
+ end
143
+
144
+ def is_xml_attribute?(object)
145
+ return false unless has_xml_options?(object)
146
+ object['xml']['attribute'] || false
147
+ end
102
148
  end
103
149
  end
@@ -1,3 +1,3 @@
1
1
  module OasParser
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
data/lib/oas_parser.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'json'
2
2
  require 'uri'
3
3
  require 'yaml'
4
+ require 'active_support/core_ext/object/blank'
5
+ require 'active_support/core_ext/hash/conversions'
6
+ require 'nokogiri'
4
7
 
5
8
  require 'addressable/uri'
6
9
  require 'json_schema'
data/oas_parser.gemspec CHANGED
@@ -24,6 +24,9 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "json_schema", "~> 0.15.0"
25
25
  spec.add_dependency "guard-rspec", "~> 4.7.3"
26
26
  spec.add_dependency "deep_merge", "~> 1.2.1"
27
+ spec.add_dependency "activesupport", "~> 5.1.2"
28
+ spec.add_dependency "builder", "~> 3.2.3"
29
+ spec.add_dependency "nokogiri", "~> 1.8.1"
27
30
 
28
31
  spec.add_development_dependency "bundler", "~> 1.16"
29
32
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oas_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Butler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-09 00:00:00.000000000 Z
11
+ date: 2018-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -66,6 +66,48 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.2.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 5.1.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 5.1.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: builder
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.2.3
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.2.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: nokogiri
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.8.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.8.1
69
111
  - !ruby/object:Gem::Dependency
70
112
  name: bundler
71
113
  requirement: !ruby/object:Gem::Requirement