openapi_first 0.7.1 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3628fb4b2c3839480899102cfa770b7dc5fbed43503689a475e3e969dc1f8c13
4
- data.tar.gz: 27fd6a6c02cd48a56e99e9e6bb7c8edc9ccbc5a0423d59c9186ec1ea3e2daecd
3
+ metadata.gz: 82bb84c8685503083fd1b5ef61e6839c706e2a2152c093af842fe96e9a0004cd
4
+ data.tar.gz: 20165b2fcb4f10004cd6ee4cab55eeec912bcac6d8d86255cb08c2f2e9f0e8a6
5
5
  SHA512:
6
- metadata.gz: e7577b4277603b753ad5b30970c1f479e9c16843400636b6718730459a8f5b1847a12d78b4582ed72d4431e9a45d9d7f1b850e39575cf08da927470a839eb371
7
- data.tar.gz: 8afb057b842fe5759878f8f6b1a4ea16bbf223bdcfcd0823dd99715b3ba3ff492be7dbf2257868fb252a14c90f820942576b3e975e394287a349c3e493277358
6
+ metadata.gz: dd403e00cdd880573c10de5949db863afd3791eb3271ef26d227e4dffe9efa9775dbb84847acbc3fd79fbc1630be1dc6e71b0c6e7362a992f6350ab2fadf4b1f
7
+ data.tar.gz: 9080c126f4a6083ed3e16bcb7f7fd5503b0efaa6633f40cfce2ce85afae4531f15c845ecb76e0138c9395626ec860a7bc9ac51df29c0d11fb2a4970583b5e86e
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0
4
+ - Add merged parameter and request body available to env at `env[OpenapiFirst::INBOX]` in request validation
5
+ - Path and query parameters with `type: boolean` now get converted to `true`/`false`
6
+ - Rename `OpenapiFirst::PARAMS` to `OpenapiFirst::PARAMETERS`
7
+
3
8
  ## 0.7.1
4
9
  - Add missing `require` to work with new version of `oas_parser`
5
10
 
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openapi_first (0.7.1)
4
+ openapi_first (0.8.0)
5
5
  hanami-router (~> 2.0.alpha2)
6
6
  hanami-utils (~> 2.0.alpha1)
7
7
  json_schemer (~> 0.2)
8
8
  multi_json (~> 1.14)
9
- oas_parser (~> 0.24)
9
+ oas_parser (~> 0.25.1)
10
10
  rack (~> 2.2)
11
11
 
12
12
  GEM
@@ -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.25.0)
60
+ oas_parser (0.25.1)
61
61
  activesupport (>= 4.0.0)
62
62
  addressable (~> 2.3)
63
63
  builder (~> 3.2.3)
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- openapi_first (0.7.1)
4
+ openapi_first (0.8.0)
5
5
  hanami-router (~> 2.0.alpha2)
6
6
  hanami-utils (~> 2.0.alpha1)
7
7
  json_schemer (~> 0.2)
8
8
  multi_json (~> 1.14)
9
- oas_parser (~> 0.24)
9
+ oas_parser (~> 0.25.1)
10
10
  rack (~> 2.2)
11
11
 
12
12
  GEM
@@ -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.25.0)
95
+ oas_parser (0.25.1)
96
96
  activesupport (>= 4.0.0)
97
97
  addressable (~> 2.3)
98
98
  builder (~> 3.2.3)
@@ -1,10 +1,10 @@
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
5
4
  require 'oas_parser'
6
5
  require 'openapi_first/definition'
7
6
  require 'openapi_first/version'
7
+ require 'openapi_first/inbox'
8
8
  require 'openapi_first/router'
9
9
  require 'openapi_first/request_validation'
10
10
  require 'openapi_first/response_validator'
@@ -13,8 +13,9 @@ require 'openapi_first/app'
13
13
 
14
14
  module OpenapiFirst
15
15
  OPERATION = 'openapi_first.operation'
16
- PARAMS = 'openapi_first.params'
16
+ PARAMETERS = 'openapi_first.parameters'
17
17
  REQUEST_BODY = 'openapi_first.parsed_request_body'
18
+ INBOX = 'openapi_first.inbox'
18
19
  HANDLER = 'openapi_first.handler'
19
20
 
20
21
  def self.load(spec_path, only: nil)
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenapiFirst
4
+ # An instance of this gets passed to handler functions as first argument.
5
+ class Inbox < Hash
6
+ attr_reader :env
7
+
8
+ def initialize(env)
9
+ @env = env
10
+ super()
11
+ end
12
+ end
13
+ end
@@ -1,15 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rack'
4
+ require_relative 'inbox'
4
5
 
5
6
  module OpenapiFirst
6
7
  class OperationResolver
7
8
  def call(env)
8
9
  operation = env[OpenapiFirst::OPERATION]
9
10
  res = Rack::Response.new
10
- params = build_params(env)
11
+ inbox = env[INBOX]
11
12
  handler = env[HANDLER]
12
- result = handler.call(params, res)
13
+ result = handler.call(inbox, res)
13
14
  res.write serialize(result) if result && res.body.empty?
14
15
  res[Rack::CONTENT_TYPE] ||= operation.content_type_for(res.status)
15
16
  res.finish
@@ -22,22 +23,5 @@ module OpenapiFirst
22
23
 
23
24
  MultiJson.dump(result)
24
25
  end
25
-
26
- def build_params(env)
27
- sources = [
28
- env[PARAMS],
29
- env[REQUEST_BODY]
30
- ].tap(&:compact!)
31
- Params.new(env).merge!(*sources)
32
- end
33
- end
34
-
35
- class Params < Hash
36
- attr_reader :env
37
-
38
- def initialize(env)
39
- @env = env
40
- super()
41
- end
42
26
  end
43
27
  end
@@ -3,6 +3,7 @@
3
3
  require 'rack'
4
4
  require 'json_schemer'
5
5
  require 'multi_json'
6
+ require_relative 'inbox'
6
7
  require_relative 'validation_format'
7
8
 
8
9
  module OpenapiFirst
@@ -15,8 +16,9 @@ module OpenapiFirst
15
16
  operation = env[OpenapiFirst::OPERATION]
16
17
  return @app.call(env) unless operation
17
18
 
19
+ env[INBOX] = Inbox.new(env)
18
20
  catch(:halt) do
19
- validate_query_parameters!(env, operation, env[PARAMS])
21
+ validate_query_parameters!(env, operation, env[PARAMETERS])
20
22
  req = Rack::Request.new(env)
21
23
  content_type = req.content_type
22
24
  return @app.call(env) unless operation.request_body
@@ -47,7 +49,7 @@ module OpenapiFirst
47
49
  if errors.any?
48
50
  halt(error_response(400, serialize_request_body_errors(errors)))
49
51
  end
50
- env[OpenapiFirst::REQUEST_BODY] = parsed_request_body
52
+ env[INBOX].merge! env[REQUEST_BODY] = parsed_request_body
51
53
  end
52
54
 
53
55
  def validate_request_content_type!(content_type, operation)
@@ -106,7 +108,8 @@ module OpenapiFirst
106
108
  if errors.any?
107
109
  halt error_response(400, serialize_query_parameter_errors(errors))
108
110
  end
109
- env[PARAMS] = params
111
+ env[PARAMETERS] = params
112
+ env[INBOX].merge! params
110
113
  end
111
114
 
112
115
  def filtered_params(json_schema, params)
@@ -137,6 +140,14 @@ module OpenapiFirst
137
140
  rescue ArgumentError
138
141
  value
139
142
  end
143
+ return to_boolean(value) if schema['type'] == 'boolean'
144
+
145
+ value
146
+ end
147
+
148
+ def to_boolean(value)
149
+ return true if value == 'true'
150
+ return false if value == 'false'
140
151
 
141
152
  value
142
153
  end
@@ -84,7 +84,7 @@ module OpenapiFirst
84
84
  normalized_path,
85
85
  to: lambda do |env|
86
86
  env[OPERATION] = operation
87
- env[PARAMS] = Utils.deep_stringify(env['router.params'])
87
+ env[PARAMETERS] = Utils.deep_stringify(env['router.params'])
88
88
  env[HANDLER] = handler
89
89
  @app.call(env)
90
90
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiFirst
4
- VERSION = '0.7.1'
4
+ VERSION = '0.8.0'
5
5
  end
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency 'hanami-utils', '~> 2.0.alpha1'
37
37
  spec.add_dependency 'json_schemer', '~> 0.2'
38
38
  spec.add_dependency 'multi_json', '~> 1.14'
39
- spec.add_dependency 'oas_parser', '~> 0.24'
39
+ spec.add_dependency 'oas_parser', '~> 0.25.1'
40
40
  spec.add_dependency 'rack', '~> 2.2'
41
41
 
42
42
  spec.add_development_dependency 'bundler', '~> 2'
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.1
4
+ version: 0.8.0
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-04-18 00:00:00.000000000 Z
11
+ date: 2020-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hanami-router
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.24'
75
+ version: 0.25.1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.24'
82
+ version: 0.25.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rack
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -190,6 +190,7 @@ files:
190
190
  - lib/openapi_first/app.rb
191
191
  - lib/openapi_first/coverage.rb
192
192
  - lib/openapi_first/definition.rb
193
+ - lib/openapi_first/inbox.rb
193
194
  - lib/openapi_first/operation.rb
194
195
  - lib/openapi_first/operation_resolver.rb
195
196
  - lib/openapi_first/request_validation.rb