rails-param-validation 0.4.4 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails-param-validation/rails/action_definition.rb +5 -1
- data/lib/rails-param-validation/rails/extensions/annotation_extension.rb +19 -1
- data/lib/rails-param-validation/rails/helper.rb +6 -1
- data/lib/rails-param-validation/rails/openapi/openapi.rb +1 -1
- data/lib/rails-param-validation/rails/tasks/openapi.rake +2 -2
- data/lib/rails-param-validation/types/types.rb +11 -2
- data/lib/rails-param-validation/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f08d88f808fa165c2d4ffae550d8c4eb6d7a69904ec8f159a29562307a072cf9
|
4
|
+
data.tar.gz: 5335b9a61723376dd56bc09182506c20536bb94cad4630a0380103e65610017c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e44809c8f21e77aa4f988cf1317b7f4c4ec312db72e9d239e70544596bbf51bc28007cbd16cb07dffe537ad3762dae09584ff14294afeebffb5a5919d9ef3f82
|
7
|
+
data.tar.gz: ad5241ed4bdaeac88b8416fb1bb63725bf4c2d83c31068425976f5ae527d955fc5b71e8993f2125b8441423ebe63e694044c850a0ed750f98a66a53e7bdecc89
|
@@ -64,7 +64,11 @@ module RailsParamValidation
|
|
64
64
|
@paths.push(method: method, path: path)
|
65
65
|
end
|
66
66
|
|
67
|
-
def finalize!(class_name, method_name)
|
67
|
+
def finalize!(class_name, method_name, base_path)
|
68
|
+
@paths.each do |path|
|
69
|
+
path[:path] = ("/#{base_path}/#{path[:path]}").gsub(/\/+$/, "").gsub(/\/{2,}/, '/')
|
70
|
+
end
|
71
|
+
|
68
72
|
@responses.each do |code, response|
|
69
73
|
name = Types::Namespace.with_namespace(
|
70
74
|
Types::Namespace.fetch(@source_file),
|
@@ -23,7 +23,7 @@ module RailsParamValidation
|
|
23
23
|
|
24
24
|
@param_definition.store_origin! class_name, method_name
|
25
25
|
RailsParamValidation.config.post_action_definition_hook.call(@param_definition)
|
26
|
-
@param_definition.finalize! class_name, method_name
|
26
|
+
@param_definition.finalize! class_name, method_name, (@base_paths || {}).fetch(self.name, self.name.underscore)
|
27
27
|
|
28
28
|
AnnotationManager.instance.annotate_method! self, name, :param_definition, @param_definition
|
29
29
|
@param_definition = nil
|
@@ -38,6 +38,11 @@ module RailsParamValidation
|
|
38
38
|
end
|
39
39
|
|
40
40
|
module ClassMethods
|
41
|
+
def base_path(path)
|
42
|
+
@base_paths ||= {}
|
43
|
+
@base_paths[self.name] = path
|
44
|
+
end
|
45
|
+
|
41
46
|
def param_definition
|
42
47
|
@param_definition || raise(StandardError.new "Annotation must be part of an operation-block")
|
43
48
|
end
|
@@ -94,10 +99,23 @@ module RailsParamValidation
|
|
94
99
|
end
|
95
100
|
|
96
101
|
def action(description = nil, flags = RailsParamValidation.config.default_action_flags)
|
102
|
+
if description.is_a?(Hash)
|
103
|
+
method = description.keys.first.to_sym
|
104
|
+
path = description.values.first
|
105
|
+
description = ""
|
106
|
+
else
|
107
|
+
method = nil
|
108
|
+
path = nil
|
109
|
+
end
|
110
|
+
|
97
111
|
@param_definition = ActionDefinition.new(Types::Namespace.caller_file)
|
98
112
|
@param_definition.description = description
|
99
113
|
flags.each { |name, value| @param_definition.add_flag name, value }
|
100
114
|
|
115
|
+
if method
|
116
|
+
@param_definition.add_path method, path
|
117
|
+
end
|
118
|
+
|
101
119
|
yield
|
102
120
|
end
|
103
121
|
end
|
@@ -7,7 +7,12 @@ module RailsParamValidation
|
|
7
7
|
|
8
8
|
def self.clean_controller_name(klass)
|
9
9
|
klass = klass.to_s if klass.is_a? Symbol
|
10
|
-
(klass.is_a?(String) ? klass : klass.name).gsub(/Controller$/, '').split(
|
10
|
+
(klass.is_a?(String) ? klass : klass.name).gsub(/Controller$/, '').split("::").join(".").to_sym
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.clean_name(klass)
|
14
|
+
klass = klass.to_s if klass.is_a? Symbol
|
15
|
+
(klass.is_a?(String) ? klass : klass.name).split("::").join(".").to_sym
|
11
16
|
end
|
12
17
|
end
|
13
18
|
|
@@ -46,7 +46,7 @@ module RailsParamValidation
|
|
46
46
|
param_definition
|
47
47
|
end
|
48
48
|
|
49
|
-
RoutingHelper.routes_for(operation.controller.to_s.underscore, operation.action.to_s).each do |route|
|
49
|
+
(operation.paths.any? ? operation.paths : RoutingHelper.routes_for(operation.controller.to_s.underscore, operation.action.to_s)).each do |route|
|
50
50
|
action_definition = {
|
51
51
|
operationId: "#{route[:method].downcase}#{route[:path].split(/[^a-zA-Z0-9]+/).map(&:downcase).map(&:capitalize).join}",
|
52
52
|
tags: [RailsHelper.clean_controller_name(operation.controller)],
|
@@ -1,6 +1,6 @@
|
|
1
1
|
namespace :openapi do
|
2
2
|
|
3
|
-
desc "Export OpenAPI definition to openapi.
|
3
|
+
desc "Export OpenAPI definition to openapi.json"
|
4
4
|
task export: :environment do
|
5
5
|
# Ensure all controllers are loaded
|
6
6
|
if defined? Zeitwerk
|
@@ -22,7 +22,7 @@ namespace :openapi do
|
|
22
22
|
print "Writing #{filename}..."
|
23
23
|
|
24
24
|
begin
|
25
|
-
File.open(filename, "w") { |f| f.write
|
25
|
+
File.open(filename, "w") { |f| f.write JSON.pretty_generate(openapi.to_object) }
|
26
26
|
puts " done."
|
27
27
|
rescue Exception => e
|
28
28
|
puts " failed."
|
@@ -50,7 +50,10 @@ class CustomT < AnnotationT
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def schema
|
53
|
-
CustomT.registry[@type]
|
53
|
+
schema = CustomT.registry[@type]
|
54
|
+
schema = CustomT.registry[@type] = schema.call if schema.is_a?(Proc)
|
55
|
+
|
56
|
+
schema
|
54
57
|
end
|
55
58
|
|
56
59
|
def self.register(type, schema)
|
@@ -89,6 +92,8 @@ module Types
|
|
89
92
|
|
90
93
|
path.pop
|
91
94
|
end
|
95
|
+
|
96
|
+
nil
|
92
97
|
end
|
93
98
|
|
94
99
|
def self.caller_file
|
@@ -140,7 +145,11 @@ module Types
|
|
140
145
|
end
|
141
146
|
|
142
147
|
def Type(type)
|
143
|
-
|
148
|
+
if type.is_a?(Class)
|
149
|
+
AnnotationTypes::CustomT.new(RailsHelper.clean_name(type))
|
150
|
+
else
|
151
|
+
AnnotationTypes::CustomT.new(Namespace.with_namespace(Namespace.fetch(Namespace.caller_file), type))
|
152
|
+
end
|
144
153
|
end
|
145
154
|
end
|
146
155
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-param-validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oskar Kirmis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Declarative parameter definition and validation for Rails
|
14
14
|
email:
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
|
-
rubygems_version: 3.3.
|
96
|
+
rubygems_version: 3.3.12
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Declarative parameter definition and validation for Rails
|