rails-param-validation 0.4.3 → 0.4.6
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 +14 -2
- data/lib/rails-param-validation/rails/tasks/openapi.rake +2 -2
- data/lib/rails-param-validation/types/types.rb +8 -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: 45f982e8976d083082c29971f2b4deef210958452f473836f9436a1af1826636
|
4
|
+
data.tar.gz: 72ddb69843370c35b464b2aedb15ea65f377b86302c3f4e47ab4ea0226f13d38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed86c39b631c509f08e16f1f1fd054255ade51d98ff5ec10bc16c94a5deebd4ee1d01c07a9f7cfa5a3d15c5be1d1eab91a9460888cd8c5ab39010e62ed888e42
|
7
|
+
data.tar.gz: c500dd124663f480ce19832e3d7d766318b0b0be5c55a0f38ed71ebdae786a752a8b94fa3fb052a16e87542d103763546def758f968b21cee928371d3e6e2100
|
@@ -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.gsub(/Controller$/, "").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)],
|
@@ -67,7 +67,19 @@ module RailsParamValidation
|
|
67
67
|
end.to_h
|
68
68
|
}
|
69
69
|
|
70
|
-
|
70
|
+
param_documentation = operation
|
71
|
+
.params
|
72
|
+
.filter { |_, v| v[:description].present? }
|
73
|
+
.map { |name, param| "* `#{name}`<br />#{param[:description]}" }
|
74
|
+
.join("\n\n")
|
75
|
+
|
76
|
+
if param_documentation.present?
|
77
|
+
param_documentation = "**Parameters**\n#{param_documentation}"
|
78
|
+
end
|
79
|
+
|
80
|
+
if param_documentation.present? || operation.description.present?
|
81
|
+
action_definition.merge!(description: "#{operation.description}\n\n#{param_documentation}".strip)
|
82
|
+
end
|
71
83
|
|
72
84
|
if body.any?
|
73
85
|
body_type_name = Types::Namespace.with_namespace(
|
@@ -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."
|
@@ -2,7 +2,7 @@ module RailsParamValidation
|
|
2
2
|
|
3
3
|
def self.register(type, schema)
|
4
4
|
AnnotationTypes::CustomT.register(
|
5
|
-
Namespace.with_namespace(Namespace.fetch(Namespace.caller_file), type),
|
5
|
+
Types::Namespace.with_namespace(Types::Namespace.fetch(Types::Namespace.caller_file), type),
|
6
6
|
schema
|
7
7
|
)
|
8
8
|
end
|
@@ -89,6 +89,8 @@ module Types
|
|
89
89
|
|
90
90
|
path.pop
|
91
91
|
end
|
92
|
+
|
93
|
+
nil
|
92
94
|
end
|
93
95
|
|
94
96
|
def self.caller_file
|
@@ -140,7 +142,11 @@ module Types
|
|
140
142
|
end
|
141
143
|
|
142
144
|
def Type(type)
|
143
|
-
|
145
|
+
if type.is_a?(Class)
|
146
|
+
AnnotationTypes::CustomT.new(RailsHelper.clean_name(type))
|
147
|
+
else
|
148
|
+
AnnotationTypes::CustomT.new(Namespace.with_namespace(Namespace.fetch(Namespace.caller_file), type))
|
149
|
+
end
|
144
150
|
end
|
145
151
|
end
|
146
152
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oskar Kirmis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-19 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.
|
96
|
+
rubygems_version: 3.3.11
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Declarative parameter definition and validation for Rails
|