oas_parser 0.8.1 → 0.9.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: 6649d62852587ebaf1bb67e555ed4993c400679f
4
- data.tar.gz: 55c7c61b31e7dec4b4cdd58ea3d63f1f2682b9c3
3
+ metadata.gz: e6ee6f96dd9a46e992d6467dabafd53b8118cfcd
4
+ data.tar.gz: c7d08a162beb83df0d38428932d52b8010330f81
5
5
  SHA512:
6
- metadata.gz: 06ca8cd65d727d3f5bfb01c949c08ea26a7c58767f644846b0e4fc69914e52875c39b6053770400465312498f31ba850d6f3a89b4830385d985131e6cc382a65
7
- data.tar.gz: 3e40006c436ba223918ffd49e02929df677b95234a943d23695314663c7d73c01e9c0478884ecbe3077c298c23a3d7b94d8fa1ec7f6c191fe70d0da86c293120
6
+ metadata.gz: c8323d13fd8614627b845d76bb16b03d113e48643ef9ecd5541f159c8ade591218ac4025286b273de4296723f0435c1857b27496243aa338b9c1bc40b79151fe
7
+ data.tar.gz: fd05eb37bda9b9e158c0e3f37464de97592440681afe808f88d885f9295ab3775907c0927f90d9d454d518b403f1f36b1153221ec874655dd0bcaf6373fb014d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oas_parser (0.8.1)
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.4)
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.3)
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.1)
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
- # OasParser
1
+ # Open API Definition Parser
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/oas_parser`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A Ruby parser for Open API Spec 3.0+ definitions.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ### Install
6
6
 
7
- ## Installation
7
+ Install the gem:
8
8
 
9
- Add this line to your application's Gemfile:
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
- And then execute:
19
+ ### Usage
16
20
 
17
- $ bundle
21
+ Here is a basic example of how you can traverse through an Open API Spec 3 Definition:
18
22
 
19
- Or install it yourself as:
23
+ ```ruby
24
+ require 'oas_parser'
20
25
 
21
- $ gem install oas_parser
26
+ definition = OasParser::Definition.resolve('petstore.yml')
27
+ # => #<OasParser::Definition>
22
28
 
23
- ## Usage
29
+ # Get a specific path
30
+ path = definition.path_by_path('/pets')
31
+ # => #<OasParser::Path>
24
32
 
25
- TODO: Write usage instructions here
33
+ # Get all paths.
34
+ definition.paths
35
+ # => [#<OasParser::Path>, ...]
26
36
 
27
- ## Development
37
+ # Get a specific endpoint by method
38
+ endpoint = path.endpoint_by_method('get')
39
+ # => #<OasParser::Endpoint>
28
40
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+ # Get all endpoints
42
+ path.endpoints
43
+ # => [#<OasParser::Endpoint>, ...]
30
44
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+ # Get endpoint description
46
+ endpoint.description
47
+ # => "Returns all pets from the system that the user has access to"
48
+ ```
32
49
 
33
- ## Contributing
50
+ Checkout the tests and `lib` directory for more classes and methods.
34
51
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/oas_parser. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
52
+ ### Development
36
53
 
37
- ## License
54
+ Run tests:
38
55
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
56
+ ```
57
+ $ rspec
58
+ ```
40
59
 
41
- ## Code of Conduct
60
+ ## Contributing
42
61
 
43
- Everyone interacting in the OasParser project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/oas_parser/blob/master/CODE_OF_CONDUCT.md).
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
@@ -1,6 +1,6 @@
1
1
  module OasParser
2
2
  class Parameter < AbstractAttribute
3
- raw_keys :name, :in, :description, :style, :schema,
3
+ raw_keys :in, :description, :style, :schema,
4
4
  :minimum, :maximum, :required
5
5
 
6
6
  attr_accessor :owner, :raw
@@ -1,9 +1,10 @@
1
1
  module OasParser
2
2
  class Property < AbstractAttribute
3
- raw_keys :name, :description, :type, :format, :minimum, :maximum,
3
+ raw_keys :description, :type, :format, :minimum, :maximum,
4
4
  :example, :default, :items
5
5
 
6
- attr_accessor :owner, :name, :schema, :raw
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
- [parse_object(object['items'])]
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
- [parse_object(object['items'])]
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
@@ -1,3 +1,3 @@
1
1
  module OasParser
2
- VERSION = '0.8.1'.freeze
2
+ VERSION = '0.9.0'.freeze
3
3
  end
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.8.1
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-07 00:00:00.000000000 Z
11
+ date: 2018-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable