rage-rb 1.10.1 → 1.12.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 +22 -0
- data/Gemfile +2 -0
- data/README.md +6 -2
- data/lib/rage/cable/adapters/base.rb +16 -0
- data/lib/rage/cable/adapters/redis.rb +127 -0
- data/lib/rage/cable/cable.rb +23 -5
- data/lib/rage/cable/channel.rb +1 -1
- data/lib/rage/cable/protocol/actioncable_v1_json.rb +32 -7
- data/lib/rage/code_loader.rb +8 -0
- data/lib/rage/configuration.rb +50 -0
- data/lib/rage/controller/api.rb +120 -29
- data/lib/rage/cookies.rb +1 -1
- data/lib/rage/ext/setup.rb +6 -4
- data/lib/rage/openapi/builder.rb +85 -0
- data/lib/rage/openapi/collector.rb +44 -0
- data/lib/rage/openapi/converter.rb +141 -0
- data/lib/rage/openapi/index.html.erb +22 -0
- data/lib/rage/openapi/nodes/method.rb +27 -0
- data/lib/rage/openapi/nodes/parent.rb +16 -0
- data/lib/rage/openapi/nodes/root.rb +56 -0
- data/lib/rage/openapi/openapi.rb +146 -0
- data/lib/rage/openapi/parser.rb +204 -0
- data/lib/rage/openapi/parsers/ext/active_record.rb +62 -0
- data/lib/rage/openapi/parsers/ext/alba.rb +285 -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 +5 -0
- metadata +19 -2
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Rage::OpenAPI::Parsers::Request
|
4
|
+
AVAILABLE_PARSERS = [
|
5
|
+
Rage::OpenAPI::Parsers::SharedReference,
|
6
|
+
Rage::OpenAPI::Parsers::YAML,
|
7
|
+
Rage::OpenAPI::Parsers::Ext::ActiveRecord
|
8
|
+
]
|
9
|
+
|
10
|
+
def self.parse(request_tag, namespace:)
|
11
|
+
parser = AVAILABLE_PARSERS.find do |parser_class|
|
12
|
+
parser = parser_class.new(namespace:)
|
13
|
+
break parser if parser.known_definition?(request_tag)
|
14
|
+
end
|
15
|
+
|
16
|
+
parser.parse(request_tag) if parser
|
17
|
+
end
|
18
|
+
end
|
@@ -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
|
@@ -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.12.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:
|
11
|
+
date: 2025-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -116,6 +116,8 @@ files:
|
|
116
116
|
- lib/rage.rb
|
117
117
|
- lib/rage/all.rb
|
118
118
|
- lib/rage/application.rb
|
119
|
+
- lib/rage/cable/adapters/base.rb
|
120
|
+
- lib/rage/cable/adapters/redis.rb
|
119
121
|
- lib/rage/cable/cable.rb
|
120
122
|
- lib/rage/cable/channel.rb
|
121
123
|
- lib/rage/cable/connection.rb
|
@@ -139,6 +141,21 @@ files:
|
|
139
141
|
- lib/rage/middleware/fiber_wrapper.rb
|
140
142
|
- lib/rage/middleware/origin_validator.rb
|
141
143
|
- lib/rage/middleware/reloader.rb
|
144
|
+
- lib/rage/openapi/builder.rb
|
145
|
+
- lib/rage/openapi/collector.rb
|
146
|
+
- lib/rage/openapi/converter.rb
|
147
|
+
- lib/rage/openapi/index.html.erb
|
148
|
+
- lib/rage/openapi/nodes/method.rb
|
149
|
+
- lib/rage/openapi/nodes/parent.rb
|
150
|
+
- lib/rage/openapi/nodes/root.rb
|
151
|
+
- lib/rage/openapi/openapi.rb
|
152
|
+
- lib/rage/openapi/parser.rb
|
153
|
+
- lib/rage/openapi/parsers/ext/active_record.rb
|
154
|
+
- lib/rage/openapi/parsers/ext/alba.rb
|
155
|
+
- lib/rage/openapi/parsers/request.rb
|
156
|
+
- lib/rage/openapi/parsers/response.rb
|
157
|
+
- lib/rage/openapi/parsers/shared_reference.rb
|
158
|
+
- lib/rage/openapi/parsers/yaml.rb
|
142
159
|
- lib/rage/params_parser.rb
|
143
160
|
- lib/rage/rails.rb
|
144
161
|
- lib/rage/request.rb
|