openapi_first 0.7.0.alpha1 → 0.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4885473ec6373b0fcfd9baace6175296f362099ba8ee73de0b8c1538b3420504
4
- data.tar.gz: 5a72ae579e67bcb17c33debb3adbcae1cdaae09ad98ccc0e1158a59719d00115
3
+ metadata.gz: 3628fb4b2c3839480899102cfa770b7dc5fbed43503689a475e3e969dc1f8c13
4
+ data.tar.gz: 27fd6a6c02cd48a56e99e9e6bb7c8edc9ccbc5a0423d59c9186ec1ea3e2daecd
5
5
  SHA512:
6
- metadata.gz: d2783c23798622b8bcc6c6f9520272d0477760d405f9879d4dc39e94b1d361b3873a87147ccef81e0ba3ec5c59e67941f645e41caf52dd221ddb915167140c6d
7
- data.tar.gz: d540387f504454feca50ea746ef87745aed68e841bc5eb734c8d2e3419676e221a8dd93404601f010e3725152cd0e0e9a2775a1646690b8f4e5b62fbd8d7ca93
6
+ metadata.gz: e7577b4277603b753ad5b30970c1f479e9c16843400636b6718730459a8f5b1847a12d78b4582ed72d4431e9a45d9d7f1b850e39575cf08da927470a839eb371
7
+ data.tar.gz: 8afb057b842fe5759878f8f6b1a4ea16bbf223bdcfcd0823dd99715b3ba3ff492be7dbf2257868fb252a14c90f820942576b3e975e394287a349c3e493277358
@@ -0,0 +1,24 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby 2.6
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6.x
20
+ - name: Build and test with Rake
21
+ run: |
22
+ gem install bundler
23
+ bundle install --jobs 4 --retry 3
24
+ bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,11 +1,19 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.6
3
- Documentation:
3
+ Style/Documentation:
4
4
  Enabled: false
5
- BlockLength:
5
+ Style/ExponentialNotation:
6
+ Enabled: true
7
+ Metrics/BlockLength:
6
8
  Exclude:
7
9
  - 'spec/**/*.rb'
8
10
  - '*.gemspec'
11
+ Layout/SpaceAroundMethodCallOperator:
12
+ Enabled: true
13
+ Lint/RaiseException:
14
+ Enabled: true
15
+ Lint/StructNewOverride:
16
+ Enabled: true
9
17
  Style/HashEachMethods:
10
18
  Enabled: false
11
19
  Style/HashTransformKeys:
data/CHANGELOG.md CHANGED
@@ -1,12 +1,19 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.7.1
4
+ - Add missing `require` to work with new version of `oas_parser`
4
5
 
6
+ ## 0.7.0
5
7
  - Make use of hanami-router, because it's fast
6
- - Remove OpenapiFirst::Coverage
7
8
  - Remove option `allow_unknown_query_paramerters`
8
9
  - Move the namespace option to Router
9
- - Convert numeric parameters to `Integer` or `Float`
10
+ - Convert numeric path and query parameters to `Integer` or `Float`
11
+ - Pass the Rack env if your action class' initializers accepts an argument
12
+ - Respec rack's `env['SCRIPT_NAME']` in router
13
+ - Add MIT license
14
+
15
+ ## 0.6.10
16
+ - Bugfix: params.env['unknown'] now returns `nil` as expected. Thanks @tristandruyen.
10
17
 
11
18
  ## 0.6.9
12
19
  - Removed radix tree, because of a bug (https://github.com/namusyaka/r2ree-ruby/issues/2)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openapi_first (0.7.0.alpha1)
4
+ openapi_first (0.7.1)
5
5
  hanami-router (~> 2.0.alpha2)
6
6
  hanami-utils (~> 2.0.alpha1)
7
7
  json_schemer (~> 0.2)
@@ -26,7 +26,7 @@ GEM
26
26
  concurrent-ruby (1.1.6)
27
27
  deep_merge (1.2.1)
28
28
  diff-lcs (1.3)
29
- ecma-re-validator (0.2.0)
29
+ ecma-re-validator (0.2.1)
30
30
  regexp_parser (~> 1.2)
31
31
  hana (1.3.5)
32
32
  hanami-router (2.0.0.alpha2)
@@ -57,7 +57,7 @@ GEM
57
57
  mustermann (= 1.1.1)
58
58
  nokogiri (1.10.9)
59
59
  mini_portile2 (~> 2.4.0)
60
- oas_parser (0.24.0)
60
+ oas_parser (0.25.0)
61
61
  activesupport (>= 4.0.0)
62
62
  addressable (~> 2.3)
63
63
  builder (~> 3.2.3)
@@ -66,12 +66,12 @@ GEM
66
66
  mustermann-contrib (~> 1.1.1)
67
67
  nokogiri
68
68
  parallel (1.19.1)
69
- parser (2.7.0.5)
69
+ parser (2.7.1.1)
70
70
  ast (~> 2.4.0)
71
- pry (0.13.0)
71
+ pry (0.13.1)
72
72
  coderay (~> 1.1)
73
73
  method_source (~> 1.0)
74
- public_suffix (4.0.3)
74
+ public_suffix (4.0.4)
75
75
  rack (2.2.2)
76
76
  rack-test (1.1.0)
77
77
  rack (>= 1.0, < 3)
@@ -92,21 +92,21 @@ GEM
92
92
  diff-lcs (>= 1.2.0, < 2.0)
93
93
  rspec-support (~> 3.9.0)
94
94
  rspec-support (3.9.2)
95
- rubocop (0.80.1)
95
+ rubocop (0.82.0)
96
96
  jaro_winkler (~> 1.5.1)
97
97
  parallel (~> 1.10)
98
98
  parser (>= 2.7.0.1)
99
99
  rainbow (>= 2.2.2, < 4.0)
100
100
  rexml
101
101
  ruby-progressbar (~> 1.7)
102
- unicode-display_width (>= 1.4.0, < 1.7)
102
+ unicode-display_width (>= 1.4.0, < 2.0)
103
103
  ruby-progressbar (1.10.1)
104
104
  ruby2_keywords (0.0.2)
105
105
  thread_safe (0.3.6)
106
106
  transproc (1.1.1)
107
- tzinfo (1.2.6)
107
+ tzinfo (1.2.7)
108
108
  thread_safe (~> 0.1)
109
- unicode-display_width (1.6.1)
109
+ unicode-display_width (1.7.0)
110
110
  uri_template (0.7.0)
111
111
  zeitwerk (2.3.0)
112
112
 
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Andreas Haller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -78,7 +78,7 @@ It works like this:
78
78
 
79
79
  - "create_pet" or "createPet" or "create pet" calls `MyApi.create_pet(params, response)`
80
80
  - "some_things.create" calls: `MyApi::SomeThings.create(params, response)`
81
- - "pets#create" calls: `MyApi::Pets::Create.new.call(params, response)`
81
+ - "pets#create" calls: `MyApi::Pets::Create.new.call(params, response)` If `MyApi::Pets::Create.new` accepts an argument, it will pass the rack `env`.
82
82
 
83
83
  These handler methods are called with two arguments:
84
84
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- openapi_first (0.7.0.alpha1)
4
+ openapi_first (0.7.1)
5
5
  hanami-router (~> 2.0.alpha2)
6
6
  hanami-utils (~> 2.0.alpha1)
7
7
  json_schemer (~> 0.2)
@@ -12,7 +12,7 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activesupport (6.0.2.1)
15
+ activesupport (6.0.2.2)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 0.7, < 2)
18
18
  minitest (~> 5.1)
@@ -30,7 +30,7 @@ GEM
30
30
  rack (>= 1.5)
31
31
  concurrent-ruby (1.1.6)
32
32
  deep_merge (1.2.1)
33
- dry-configurable (0.11.3)
33
+ dry-configurable (0.11.5)
34
34
  concurrent-ruby (~> 1.0)
35
35
  dry-core (~> 0.4, >= 0.4.7)
36
36
  dry-equalizer (~> 0.2)
@@ -52,9 +52,9 @@ GEM
52
52
  dry-equalizer (~> 0.3)
53
53
  dry-inflector (~> 0.1, >= 0.1.2)
54
54
  dry-logic (~> 1.0, >= 1.0.2)
55
- ecma-re-validator (0.2.0)
55
+ ecma-re-validator (0.2.1)
56
56
  regexp_parser (~> 1.2)
57
- grape (1.3.0)
57
+ grape (1.3.2)
58
58
  activesupport
59
59
  builder
60
60
  dry-types (>= 1.1)
@@ -92,7 +92,7 @@ GEM
92
92
  mustermann (>= 1.0.0)
93
93
  nokogiri (1.10.9)
94
94
  mini_portile2 (~> 2.4.0)
95
- oas_parser (0.24.0)
95
+ oas_parser (0.25.0)
96
96
  activesupport (>= 4.0.0)
97
97
  addressable (~> 2.3)
98
98
  builder (~> 3.2.3)
@@ -100,8 +100,8 @@ GEM
100
100
  hash-deep-merge
101
101
  mustermann-contrib (~> 1.1.1)
102
102
  nokogiri
103
- openapi_parser (0.8.0)
104
- public_suffix (4.0.3)
103
+ openapi_parser (0.10.0)
104
+ public_suffix (4.0.4)
105
105
  rack (2.2.2)
106
106
  rack-accept (0.4.5)
107
107
  rack (>= 0.4)
@@ -121,7 +121,7 @@ GEM
121
121
  thread_safe (0.3.6)
122
122
  tilt (2.0.10)
123
123
  transproc (1.1.1)
124
- tzinfo (1.2.6)
124
+ tzinfo (1.2.7)
125
125
  thread_safe (~> 0.1)
126
126
  uri_template (0.7.0)
127
127
  zeitwerk (2.3.0)
data/lib/openapi_first.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
+ require 'oas_parser/path' # TODO: Remove when Nexmo/oas_parser/pull/49 is merged
4
5
  require 'oas_parser'
5
6
  require 'openapi_first/definition'
6
7
  require 'openapi_first/version'
@@ -46,5 +47,5 @@ module OpenapiFirst
46
47
  end
47
48
 
48
49
  class Error < StandardError; end
49
- # Your code goes here...
50
+ class ResponseCodeNotFoundError < Error; end
50
51
  end
@@ -28,6 +28,10 @@ module OpenapiFirst
28
28
  .response_by_code(status.to_s, use_default: true)
29
29
  .content
30
30
  content.keys[0] if content
31
+ rescue OasParser::ResponseCodeNotFound
32
+ operation_name = "#{method.upcase} #{path}"
33
+ message = "Response status code or default not found: #{status} for '#{operation_name}'" # rubocop:disable Layout/LineLength
34
+ raise OpenapiFirst::ResponseCodeNotFoundError, message
31
35
  end
32
36
 
33
37
  private
@@ -37,7 +37,7 @@ module OpenapiFirst
37
37
 
38
38
  def initialize(env)
39
39
  @env = env
40
- super
40
+ super()
41
41
  end
42
42
  end
43
43
  end
@@ -16,9 +16,8 @@ module OpenapiFirst
16
16
  end
17
17
 
18
18
  def call(env)
19
- route = @router.recognize(env)
20
- return route.endpoint.call(env) if route.routable?
21
-
19
+ endpoint = find_endpoint(env)
20
+ return endpoint.call(env) if endpoint
22
21
  return @parent_app.call(env) if @parent_app
23
22
 
24
23
  NOT_FOUND
@@ -37,7 +36,11 @@ module OpenapiFirst
37
36
  module_name, klass_name = name.split('#')
38
37
  const = find_const(@namespace, module_name)
39
38
  klass = find_const(const, klass_name)
40
- return ->(params, res) { klass.new.call(params, res) }
39
+ if klass.instance_method(:initialize).arity.zero?
40
+ return ->(params, res) { klass.new.call(params, res) }
41
+ end
42
+
43
+ return ->(params, res) { klass.new(params.env).call(params, res) }
41
44
  end
42
45
  method_name = Utils.underscore(name)
43
46
  return unless @namespace.respond_to?(method_name)
@@ -47,6 +50,15 @@ module OpenapiFirst
47
50
 
48
51
  private
49
52
 
53
+ def find_endpoint(env)
54
+ original_path_info = env[Rack::PATH_INFO]
55
+ # Overwrite PATH_INFO temporarily, because hanami-router does not respect SCRIPT_NAME # rubocop:disable Layout/LineLength
56
+ env[Rack::PATH_INFO] = Rack::Request.new(env).path
57
+ @router.recognize(env).endpoint
58
+ ensure
59
+ env[Rack::PATH_INFO] = original_path_info
60
+ end
61
+
50
62
  def find_const(parent, name)
51
63
  name = Utils.classify(name)
52
64
  return unless parent.const_defined?(name, false)
@@ -64,7 +76,7 @@ module OpenapiFirst
64
76
  end
65
77
  handler = find_handler(operation.operation_id)
66
78
  if handler.nil?
67
- warn "could not find handler for '#{operation.operation_id}' (#{operation.method} #{operation.path}). I am ignoring this operation." # rubocop:disable Layout/LineLength
79
+ warn "#{self.class.name} cannot not find handler for '#{operation.operation_id}' (#{operation.method} #{operation.path}). This operation will be ignored." # rubocop:disable Layout/LineLength
68
80
  next
69
81
  end
70
82
  router.public_send(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiFirst
4
- VERSION = '0.7.0.alpha1'
4
+ VERSION = '0.7.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_first
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.alpha1
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Haller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-23 00:00:00.000000000 Z
11
+ date: 2020-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hanami-router
@@ -158,6 +158,7 @@ extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
160
  - ".github/CODEOWNERS"
161
+ - ".github/workflows/ruby.yml"
161
162
  - ".gitignore"
162
163
  - ".rspec"
163
164
  - ".rubocop.yml"
@@ -165,6 +166,7 @@ files:
165
166
  - CHANGELOG.md
166
167
  - Gemfile
167
168
  - Gemfile.lock
169
+ - LICENSE.txt
168
170
  - README.md
169
171
  - Rakefile
170
172
  - benchmarks/Gemfile
@@ -216,9 +218,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
216
218
  version: '0'
217
219
  required_rubygems_version: !ruby/object:Gem::Requirement
218
220
  requirements:
219
- - - ">"
221
+ - - ">="
220
222
  - !ruby/object:Gem::Version
221
- version: 1.3.1
223
+ version: '0'
222
224
  requirements: []
223
225
  rubygems_version: 3.1.2
224
226
  signing_key: