openapi_first 1.3.4 → 1.3.5
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 631b8fea22128020990af7edb3605d0e842d04b0f876affb4277b3f81b571921
|
4
|
+
data.tar.gz: 3fc61f1ca41bb0d380c188681bad5477c36c6cbeeeec5fabf1700d468987aae5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2b1210a029a62742928ebf2e285a58d9d48d2a809373cce1652a13f8b538675b37be361c99625d6e0bb6cf70ea58ebbaba7486f8ac73896cf5989b74257cd06
|
7
|
+
data.tar.gz: 0e5d4798b159fd71af8da50703644f71a16cc276bfdafcaff3cf64777042d6ed9b78ac62ba1dfe07cbd1026cf8d359b77124a5abe39d239030c5d5f5b967b12c
|
data/CHANGELOG.md
CHANGED
@@ -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
|
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.5
|
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-19 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
|