openapi_first 1.3.4 → 1.3.6
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/CHANGELOG.md +8 -0
- data/lib/openapi_first/definition/path_item.rb +7 -0
- data/lib/openapi_first/definition/path_template.rb +40 -0
- data/lib/openapi_first/definition.rb +3 -6
- data/lib/openapi_first/middlewares/response_validation.rb +9 -1
- data/lib/openapi_first/version.rb +1 -1
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 221362a78a788c449a8c11af9c40fc91bf307c82ee79d0931c94f39bb22901bc
|
4
|
+
data.tar.gz: d9b806ed56371199552b4081d2b6b220279b925b9fdbdaa90ce47623c86e4bff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c5ceac8c85f7d074983e5d237febe8ecf9ec3414a5ecb1a5bd8af43259eb2c83621ac867ca9b1d5420a3dda7518e131ed2ac1f08b86d71fa6fdfccbf76e1885
|
7
|
+
data.tar.gz: 92c44316bf96d31841a959898efcd20e08bc223f233e26af253cc3575dbf29680b13e27ab628eb9bb9544371c08c0d7aea42b5aaf8bef75d369299067e6eb0ca
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 1.3.6
|
6
|
+
|
7
|
+
- Fix Rack 2 / Rails 6 compatibility ([#246](https://github.com/ahx/openapi_first/issues/246)
|
8
|
+
|
9
|
+
## 1.3.5
|
10
|
+
|
11
|
+
- Added support for `/some/{kebab-cased}` path parameters ([#245](https://github.com/ahx/openapi_first/issues/245))
|
12
|
+
|
5
13
|
## 1.3.4
|
6
14
|
|
7
15
|
- Fixed handling "binary" format in optional multipart file uploads
|
@@ -1,19 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'forwardable'
|
3
4
|
require_relative 'operation'
|
5
|
+
require_relative 'path_template'
|
4
6
|
|
5
7
|
module OpenapiFirst
|
6
8
|
class Definition
|
7
9
|
# A pathItem as defined in the OpenAPI document.
|
8
10
|
class PathItem
|
11
|
+
extend Forwardable
|
12
|
+
|
9
13
|
def initialize(path, path_item_object, openapi_version:)
|
10
14
|
@path = path
|
11
15
|
@path_item_object = path_item_object
|
12
16
|
@openapi_version = openapi_version
|
17
|
+
@path_template = PathTemplate.new(path)
|
13
18
|
end
|
14
19
|
|
15
20
|
attr_reader :path
|
16
21
|
|
22
|
+
def_delegator :@path_template, :match
|
23
|
+
|
17
24
|
def operation(request_method)
|
18
25
|
return unless @path_item_object[request_method]
|
19
26
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenapiFirst
|
4
|
+
class Definition
|
5
|
+
# @visibility private
|
6
|
+
class PathTemplate
|
7
|
+
# See also https://spec.openapis.org/oas/v3.1.0#path-templating
|
8
|
+
TEMPLATE_EXPRESSION = /(\{[^}]+\})/
|
9
|
+
TEMPLATE_EXPRESSION_NAME = /\{([^}]+)\}/
|
10
|
+
ALLOWED_PARAMETER_CHARACTERS = %r{([^/?#]+)}
|
11
|
+
|
12
|
+
def initialize(template)
|
13
|
+
@template = template
|
14
|
+
@names = template.scan(TEMPLATE_EXPRESSION_NAME).flatten
|
15
|
+
@pattern = build_pattern(template)
|
16
|
+
end
|
17
|
+
|
18
|
+
def match(path)
|
19
|
+
return {} if path == @template
|
20
|
+
return if @names.empty?
|
21
|
+
|
22
|
+
matches = path.match(@pattern)
|
23
|
+
return unless matches
|
24
|
+
|
25
|
+
values = matches.captures
|
26
|
+
@names.zip(values).to_h
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def build_pattern(template)
|
32
|
+
parts = template.split(TEMPLATE_EXPRESSION).map! do |part|
|
33
|
+
part.start_with?('{') ? ALLOWED_PARAMETER_CHARACTERS : Regexp.escape(part)
|
34
|
+
end
|
35
|
+
|
36
|
+
%r{^#{parts.join}/?$}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'mustermann'
|
4
3
|
require_relative 'definition/path_item'
|
5
4
|
require_relative 'runtime_request'
|
6
5
|
require_relative 'request_validation/validator'
|
@@ -99,14 +98,12 @@ module OpenapiFirst
|
|
99
98
|
end
|
100
99
|
|
101
100
|
def search_for_path_item(request_path)
|
102
|
-
|
103
|
-
|
104
|
-
path_params = template.params(request_path)
|
101
|
+
path_items.find do |path_item|
|
102
|
+
path_params = path_item.match(request_path)
|
105
103
|
next unless path_params
|
106
|
-
next unless path_params.size == template.names.size
|
107
104
|
|
108
105
|
return [
|
109
|
-
|
106
|
+
path_item,
|
110
107
|
path_params
|
111
108
|
]
|
112
109
|
end
|
@@ -24,13 +24,21 @@ module OpenapiFirst
|
|
24
24
|
def call(env)
|
25
25
|
request = find_request(env)
|
26
26
|
status, headers, body = @app.call(env)
|
27
|
-
body = body
|
27
|
+
body = read_body(body)
|
28
28
|
request.validate_response(Rack::Response[status, headers, body], raise_error: true)
|
29
29
|
[status, headers, body]
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
+
def read_body(body)
|
35
|
+
return body.to_ary if body.respond_to?(:to_ary)
|
36
|
+
|
37
|
+
result = []
|
38
|
+
body.each { |part| result << part }
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
34
42
|
def find_request(env)
|
35
43
|
env[REQUEST] ||= @definition.request(Rack::Request.new(env))
|
36
44
|
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: 1.3.
|
4
|
+
version: 1.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Haller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hana
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.15'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: mustermann
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 3.0.0
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 3.0.0
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: openapi_parameters
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +108,7 @@ files:
|
|
122
108
|
- lib/openapi_first/definition.rb
|
123
109
|
- lib/openapi_first/definition/operation.rb
|
124
110
|
- lib/openapi_first/definition/path_item.rb
|
111
|
+
- lib/openapi_first/definition/path_template.rb
|
125
112
|
- lib/openapi_first/definition/request_body.rb
|
126
113
|
- lib/openapi_first/definition/response.rb
|
127
114
|
- lib/openapi_first/definition/responses.rb
|