rage-rb 1.10.0 → 1.11.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 +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile +1 -0
- data/README.md +5 -0
- data/lib/rage/code_loader.rb +8 -0
- data/lib/rage/configuration.rb +23 -0
- data/lib/rage/controller/api.rb +27 -12
- data/lib/rage/ext/setup.rb +7 -5
- data/lib/rage/openapi/builder.rb +84 -0
- data/lib/rage/openapi/collector.rb +43 -0
- data/lib/rage/openapi/converter.rb +138 -0
- data/lib/rage/openapi/index.html.erb +22 -0
- data/lib/rage/openapi/nodes/method.rb +24 -0
- data/lib/rage/openapi/nodes/parent.rb +13 -0
- data/lib/rage/openapi/nodes/root.rb +49 -0
- data/lib/rage/openapi/openapi.rb +146 -0
- data/lib/rage/openapi/parser.rb +193 -0
- data/lib/rage/openapi/parsers/ext/active_record.rb +62 -0
- data/lib/rage/openapi/parsers/ext/alba.rb +281 -0
- data/lib/rage/openapi/parsers/request.rb +18 -0
- data/lib/rage/openapi/parsers/response.rb +19 -0
- data/lib/rage/openapi/parsers/shared_reference.rb +25 -0
- data/lib/rage/openapi/parsers/yaml.rb +66 -0
- data/lib/rage/router/backend.rb +1 -0
- data/lib/rage/version.rb +1 -1
- data/lib/rage-rb.rb +6 -1
- metadata +17 -2
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Rage::OpenAPI::Parsers::Response
|
4
|
+
AVAILABLE_PARSERS = [
|
5
|
+
Rage::OpenAPI::Parsers::SharedReference,
|
6
|
+
Rage::OpenAPI::Parsers::Ext::ActiveRecord,
|
7
|
+
Rage::OpenAPI::Parsers::Ext::Alba,
|
8
|
+
Rage::OpenAPI::Parsers::YAML
|
9
|
+
]
|
10
|
+
|
11
|
+
def self.parse(response_tag, namespace:)
|
12
|
+
parser = AVAILABLE_PARSERS.find do |parser_class|
|
13
|
+
parser = parser_class.new(namespace:)
|
14
|
+
break parser if parser.known_definition?(response_tag)
|
15
|
+
end
|
16
|
+
|
17
|
+
parser.parse(response_tag) if parser
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Rage::OpenAPI::Parsers::SharedReference
|
4
|
+
def initialize(**)
|
5
|
+
end
|
6
|
+
|
7
|
+
def known_definition?(str)
|
8
|
+
str.start_with?("#/components")
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse(component_path)
|
12
|
+
{ "$ref" => component_path } if valid_components_ref?(component_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def valid_components_ref?(component_path)
|
18
|
+
shared_components = Rage::OpenAPI.__shared_components
|
19
|
+
return false if shared_components.empty?
|
20
|
+
|
21
|
+
!!component_path[2..].split("/").reduce(shared_components) do |components, component_key|
|
22
|
+
components[component_key] if components
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Rage::OpenAPI::Parsers::YAML
|
4
|
+
def initialize(**)
|
5
|
+
end
|
6
|
+
|
7
|
+
def known_definition?(yaml)
|
8
|
+
object = YAML.safe_load(yaml) rescue nil
|
9
|
+
!!object && object.is_a?(Enumerable)
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse(yaml)
|
13
|
+
__parse(YAML.safe_load(yaml))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def __parse(object)
|
19
|
+
spec = {}
|
20
|
+
|
21
|
+
if object.is_a?(Hash)
|
22
|
+
spec = { "type" => "object", "properties" => {} }
|
23
|
+
|
24
|
+
object.each do |key, value|
|
25
|
+
spec["properties"][key] = if value.is_a?(Enumerable)
|
26
|
+
__parse(value)
|
27
|
+
else
|
28
|
+
type_to_spec(value)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
elsif object.is_a?(Array) && object.length == 1
|
33
|
+
spec = { "type" => "array", "items" => object[0].is_a?(Enumerable) ? __parse(object[0]) : type_to_spec(object[0]) }
|
34
|
+
|
35
|
+
elsif object.is_a?(Array)
|
36
|
+
spec = { "type" => "string", "enum" => object }
|
37
|
+
end
|
38
|
+
|
39
|
+
spec
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def type_to_spec(type)
|
45
|
+
case type
|
46
|
+
when "Integer"
|
47
|
+
{ "type" => "integer" }
|
48
|
+
when "Float"
|
49
|
+
{ "type" => "number", "format" => "float" }
|
50
|
+
when "Numeric"
|
51
|
+
{ "type" => "number" }
|
52
|
+
when "Boolean"
|
53
|
+
{ "type" => "boolean" }
|
54
|
+
when "Hash"
|
55
|
+
{ "type" => "object" }
|
56
|
+
when "Date"
|
57
|
+
{ "type" => "string", "format" => "date" }
|
58
|
+
when "DateTime", "Time"
|
59
|
+
{ "type" => "string", "format" => "date-time" }
|
60
|
+
when "String"
|
61
|
+
{ "type" => "string" }
|
62
|
+
else
|
63
|
+
{ "type" => "string", "enum" => [type] }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/rage/router/backend.rb
CHANGED
data/lib/rage/version.rb
CHANGED
data/lib/rage-rb.rb
CHANGED
@@ -18,6 +18,10 @@ module Rage
|
|
18
18
|
Rage::Cable
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.openapi
|
22
|
+
Rage::OpenAPI
|
23
|
+
end
|
24
|
+
|
21
25
|
def self.routes
|
22
26
|
Rage::Router::DSL.new(__router)
|
23
27
|
end
|
@@ -63,7 +67,7 @@ module Rage
|
|
63
67
|
patch = proc do
|
64
68
|
is_connected = ActiveRecord::Base.connection_pool rescue false
|
65
69
|
if is_connected
|
66
|
-
puts "INFO: Patching ActiveRecord::ConnectionPool"
|
70
|
+
Iodine.on_state(:pre_start) { puts "INFO: Patching ActiveRecord::ConnectionPool" }
|
67
71
|
Iodine.on_state(:on_start) do
|
68
72
|
ActiveRecord::Base.connection_handler.connection_pool_list(:all).each do |pool|
|
69
73
|
pool.extend(Rage::Ext::ActiveRecord::ConnectionPool)
|
@@ -121,6 +125,7 @@ module Rage
|
|
121
125
|
autoload :Cookies, "rage/cookies"
|
122
126
|
autoload :Session, "rage/session"
|
123
127
|
autoload :Cable, "rage/cable/cable"
|
128
|
+
autoload :OpenAPI, "rage/openapi/openapi"
|
124
129
|
end
|
125
130
|
|
126
131
|
module RageController
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rage-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Samoilov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -139,6 +139,21 @@ files:
|
|
139
139
|
- lib/rage/middleware/fiber_wrapper.rb
|
140
140
|
- lib/rage/middleware/origin_validator.rb
|
141
141
|
- lib/rage/middleware/reloader.rb
|
142
|
+
- lib/rage/openapi/builder.rb
|
143
|
+
- lib/rage/openapi/collector.rb
|
144
|
+
- lib/rage/openapi/converter.rb
|
145
|
+
- lib/rage/openapi/index.html.erb
|
146
|
+
- lib/rage/openapi/nodes/method.rb
|
147
|
+
- lib/rage/openapi/nodes/parent.rb
|
148
|
+
- lib/rage/openapi/nodes/root.rb
|
149
|
+
- lib/rage/openapi/openapi.rb
|
150
|
+
- lib/rage/openapi/parser.rb
|
151
|
+
- lib/rage/openapi/parsers/ext/active_record.rb
|
152
|
+
- lib/rage/openapi/parsers/ext/alba.rb
|
153
|
+
- lib/rage/openapi/parsers/request.rb
|
154
|
+
- lib/rage/openapi/parsers/response.rb
|
155
|
+
- lib/rage/openapi/parsers/shared_reference.rb
|
156
|
+
- lib/rage/openapi/parsers/yaml.rb
|
142
157
|
- lib/rage/params_parser.rb
|
143
158
|
- lib/rage/rails.rb
|
144
159
|
- lib/rage/request.rb
|