oas_parser 0.8.1 → 0.9.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 +4 -4
- data/README.md +39 -20
- data/lib/oas_parser/abstract_attribute.rb +10 -0
- data/lib/oas_parser/parameter.rb +1 -1
- data/lib/oas_parser/property.rb +3 -2
- data/lib/oas_parser/response_parser.rb +35 -2
- data/lib/oas_parser/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6ee6f96dd9a46e992d6467dabafd53b8118cfcd
|
4
|
+
data.tar.gz: c7d08a162beb83df0d38428932d52b8010330f81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8323d13fd8614627b845d76bb16b03d113e48643ef9ecd5541f159c8ade591218ac4025286b273de4296723f0435c1857b27496243aa338b9c1bc40b79151fe
|
7
|
+
data.tar.gz: fd05eb37bda9b9e158c0e3f37464de97592440681afe808f88d885f9295ab3775907c0927f90d9d454d518b403f1f36b1153221ec874655dd0bcaf6373fb014d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
oas_parser (0.
|
4
|
+
oas_parser (0.9.0)
|
5
5
|
activesupport (~> 5.1.2)
|
6
6
|
addressable (~> 2.3)
|
7
7
|
builder (~> 3.2.3)
|
@@ -13,7 +13,7 @@ PATH
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
15
15
|
specs:
|
16
|
-
activesupport (5.1.
|
16
|
+
activesupport (5.1.5)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (~> 0.7)
|
19
19
|
minitest (~> 5.1)
|
@@ -42,7 +42,7 @@ GEM
|
|
42
42
|
guard (~> 2.1)
|
43
43
|
guard-compat (~> 1.1)
|
44
44
|
rspec (>= 2.99.0, < 4.0)
|
45
|
-
i18n (0.9.
|
45
|
+
i18n (0.9.5)
|
46
46
|
concurrent-ruby (~> 1.0)
|
47
47
|
json (2.1.0)
|
48
48
|
json_schema (0.15.0)
|
@@ -63,7 +63,7 @@ GEM
|
|
63
63
|
pry (0.11.3)
|
64
64
|
coderay (~> 1.1.0)
|
65
65
|
method_source (~> 0.9.0)
|
66
|
-
public_suffix (3.0.
|
66
|
+
public_suffix (3.0.2)
|
67
67
|
rake (10.5.0)
|
68
68
|
rb-fsevent (0.10.2)
|
69
69
|
rb-inotify (0.9.10)
|
data/README.md
CHANGED
@@ -1,43 +1,62 @@
|
|
1
|
-
#
|
1
|
+
# Open API Definition Parser
|
2
2
|
|
3
|
-
|
3
|
+
A Ruby parser for Open API Spec 3.0+ definitions.
|
4
4
|
|
5
|
-
|
5
|
+
### Install
|
6
6
|
|
7
|
-
|
7
|
+
Install the gem:
|
8
8
|
|
9
|
-
|
9
|
+
```
|
10
|
+
$ gem install oas_parser
|
11
|
+
```
|
12
|
+
|
13
|
+
Or add it to your Gemfile:
|
10
14
|
|
11
15
|
```ruby
|
12
16
|
gem 'oas_parser'
|
13
17
|
```
|
14
18
|
|
15
|
-
|
19
|
+
### Usage
|
16
20
|
|
17
|
-
|
21
|
+
Here is a basic example of how you can traverse through an Open API Spec 3 Definition:
|
18
22
|
|
19
|
-
|
23
|
+
```ruby
|
24
|
+
require 'oas_parser'
|
20
25
|
|
21
|
-
|
26
|
+
definition = OasParser::Definition.resolve('petstore.yml')
|
27
|
+
# => #<OasParser::Definition>
|
22
28
|
|
23
|
-
|
29
|
+
# Get a specific path
|
30
|
+
path = definition.path_by_path('/pets')
|
31
|
+
# => #<OasParser::Path>
|
24
32
|
|
25
|
-
|
33
|
+
# Get all paths.
|
34
|
+
definition.paths
|
35
|
+
# => [#<OasParser::Path>, ...]
|
26
36
|
|
27
|
-
|
37
|
+
# Get a specific endpoint by method
|
38
|
+
endpoint = path.endpoint_by_method('get')
|
39
|
+
# => #<OasParser::Endpoint>
|
28
40
|
|
29
|
-
|
41
|
+
# Get all endpoints
|
42
|
+
path.endpoints
|
43
|
+
# => [#<OasParser::Endpoint>, ...]
|
30
44
|
|
31
|
-
|
45
|
+
# Get endpoint description
|
46
|
+
endpoint.description
|
47
|
+
# => "Returns all pets from the system that the user has access to"
|
48
|
+
```
|
32
49
|
|
33
|
-
|
50
|
+
Checkout the tests and `lib` directory for more classes and methods.
|
34
51
|
|
35
|
-
|
52
|
+
### Development
|
36
53
|
|
37
|
-
|
54
|
+
Run tests:
|
38
55
|
|
39
|
-
|
56
|
+
```
|
57
|
+
$ rspec
|
58
|
+
```
|
40
59
|
|
41
|
-
##
|
60
|
+
## Contributing
|
42
61
|
|
43
|
-
|
62
|
+
Contributions are welcome, please follow [GitHub Flow](https://guides.github.com/introduction/flow/index.html)
|
@@ -2,6 +2,16 @@ module OasParser
|
|
2
2
|
class AbstractAttribute
|
3
3
|
include OasParser::RawAccessor
|
4
4
|
|
5
|
+
def name(format = nil)
|
6
|
+
default = @name || raw['name']
|
7
|
+
return default unless format
|
8
|
+
case format
|
9
|
+
when 'text/xml'
|
10
|
+
has_xml_name? ? xml_name : default
|
11
|
+
else default
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
def enum
|
6
16
|
raw['enum'] || (schema ? schema['enum'] : nil)
|
7
17
|
end
|
data/lib/oas_parser/parameter.rb
CHANGED
data/lib/oas_parser/property.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module OasParser
|
2
2
|
class Property < AbstractAttribute
|
3
|
-
raw_keys :
|
3
|
+
raw_keys :description, :type, :format, :minimum, :maximum,
|
4
4
|
:example, :default, :items
|
5
5
|
|
6
|
-
attr_accessor :owner, :
|
6
|
+
attr_accessor :owner, :schema, :raw
|
7
|
+
attr_writer :name
|
7
8
|
|
8
9
|
def initialize(owner, schema, name, raw)
|
9
10
|
@owner = owner
|
@@ -31,6 +31,19 @@ module OasParser
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
xml_document.xpath('//__array_attributes').each do |attributes|
|
35
|
+
attributes.children.each do |attribute|
|
36
|
+
next unless attribute.class == Nokogiri::XML::Element
|
37
|
+
|
38
|
+
parameter = {}
|
39
|
+
parameter['example'] = attribute.css('example').text if attribute.css('example')
|
40
|
+
parameter['type'] = attribute.css('type').text if attribute.css('type')
|
41
|
+
|
42
|
+
attribute.parent.parent.parent[attribute.name] = parameter_value(parameter)
|
43
|
+
end
|
44
|
+
attributes.parent.remove
|
45
|
+
end
|
46
|
+
|
34
47
|
xml_document.xpath('//__text').each do |attribute|
|
35
48
|
value = attribute.children.last.content
|
36
49
|
attribute.parent.content = value
|
@@ -108,14 +121,34 @@ module OasParser
|
|
108
121
|
def parse_array(object)
|
109
122
|
raise StandardError.new("Not an array") unless object['type'] == 'array'
|
110
123
|
|
124
|
+
attributes = {}
|
125
|
+
|
126
|
+
if object['properties']
|
127
|
+
if @mode == 'xml'
|
128
|
+
object['properties'].each do |key, value|
|
129
|
+
if is_xml_attribute?(value)
|
130
|
+
attributes[key] = value
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
111
136
|
case object['items']['type']
|
112
137
|
when 'object'
|
113
|
-
|
138
|
+
if attributes.any? && @mode == 'xml'
|
139
|
+
[parse_object(object['items']), { '__array_attributes' => attributes }]
|
140
|
+
else
|
141
|
+
[parse_object(object['items'])]
|
142
|
+
end
|
114
143
|
else
|
115
144
|
if object['items']
|
116
145
|
# Handle objects with missing type
|
117
146
|
object['items']['type'] = 'object'
|
118
|
-
|
147
|
+
if @mode == 'xml'
|
148
|
+
[parse_object(object['items']), { '__array_attributes' => attributes }]
|
149
|
+
else
|
150
|
+
[parse_object(object['items'])]
|
151
|
+
end
|
119
152
|
else
|
120
153
|
raise StandardError.new("parse_array: Don't know how to parse object")
|
121
154
|
end
|
data/lib/oas_parser/version.rb
CHANGED
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.
|
4
|
+
version: 0.9.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-02-
|
11
|
+
date: 2018-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|