rails-param-validation 0.3.2 → 0.4.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/lib/rails-param-validation/rails/action_definition.rb +7 -3
- data/lib/rails-param-validation/rails/extensions/annotation_extension.rb +1 -1
- data/lib/rails-param-validation/rails/extensions/custom_type_extension.rb +2 -1
- data/lib/rails-param-validation/rails/helper.rb +1 -1
- data/lib/rails-param-validation/rails/openapi/openapi.rb +4 -1
- data/lib/rails-param-validation/types/types.rb +57 -2
- data/lib/rails-param-validation/validators/constant.rb +1 -1
- 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: 9f36c1fb9e60cc1162e7a1baae9953e77441018a1a12825d72b97731a645d760
|
4
|
+
data.tar.gz: d4100447e253b96a02cb407dcde58c941ac44f6fb3046f1a54dd17172bcdad6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88ff549087489e388b4341a3646930ce38a07f6275fe1649f59181e2940f2ce4086a644300f7574760c654eac71c2d202ffb7ccd7d3b0ac1392ff88fa3e76ee0
|
7
|
+
data.tar.gz: ab7013451be92067596264d5e7f2689be20269276b0850936bc589ac43fe27276e0279344fa74786016f90fdcb77c8cf257f157793a4f8516a16f31dbd0e1dd7
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module RailsParamValidation
|
2
2
|
|
3
3
|
class ActionDefinition
|
4
|
-
attr_reader :params, :request_body_type, :paths, :responses, :controller, :action, :security
|
4
|
+
attr_reader :params, :request_body_type, :paths, :responses, :controller, :action, :security, :source_file
|
5
5
|
attr_accessor :description
|
6
6
|
|
7
|
-
def initialize
|
7
|
+
def initialize(source_file)
|
8
8
|
@params = {}
|
9
9
|
@paths = []
|
10
10
|
@param_validation_enabled = true
|
@@ -12,6 +12,7 @@ module RailsParamValidation
|
|
12
12
|
@request_body_type = RailsParamValidation.config.default_body_content_type if defined?(Rails)
|
13
13
|
@responses = {}
|
14
14
|
@flags = {}
|
15
|
+
@source_file = source_file
|
15
16
|
@security = []
|
16
17
|
end
|
17
18
|
|
@@ -65,7 +66,10 @@ module RailsParamValidation
|
|
65
66
|
|
66
67
|
def finalize!(class_name, method_name)
|
67
68
|
@responses.each do |code, response|
|
68
|
-
name =
|
69
|
+
name = Types::Namespace.with_namespace(
|
70
|
+
Types::Namespace.fetch(@source_file),
|
71
|
+
"#{RailsHelper.clean_controller_name(class_name)}.#{method_name.to_s.camelcase}.#{Rack::Utils::SYMBOL_TO_STATUS_CODE.key(code).to_s.camelize}Response".to_sym
|
72
|
+
)
|
69
73
|
AnnotationTypes::CustomT.register(name, response[:schema])
|
70
74
|
|
71
75
|
response.merge!(schema: AnnotationTypes::CustomT.new(name))
|
@@ -94,7 +94,7 @@ module RailsParamValidation
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def action(description = nil, flags = RailsParamValidation.config.default_action_flags)
|
97
|
-
@param_definition = ActionDefinition.new
|
97
|
+
@param_definition = ActionDefinition.new(Types::Namespace.caller_file)
|
98
98
|
@param_definition.description = description
|
99
99
|
flags.each { |name, value| @param_definition.add_flag name, value }
|
100
100
|
|
@@ -6,7 +6,8 @@ module RailsParamValidation
|
|
6
6
|
|
7
7
|
module ClassMethods
|
8
8
|
def declare(type, schema)
|
9
|
-
|
9
|
+
namespace = Types::Namespace.fetch(Types::Namespace.caller_file)
|
10
|
+
RailsParamValidation::AnnotationTypes::CustomT.register Types::Namespace.with_namespace(namespace, type), schema
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -7,7 +7,7 @@ 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('::').last.capitalize.to_sym
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -70,7 +70,10 @@ module RailsParamValidation
|
|
70
70
|
action_definition.merge!(summary: operation.description) if operation.description.present?
|
71
71
|
|
72
72
|
if body.any?
|
73
|
-
body_type_name =
|
73
|
+
body_type_name = Types::Namespace.with_namespace(
|
74
|
+
Types::Namespace.fetch(operation.source_file),
|
75
|
+
"#{RailsHelper.clean_controller_name operation.controller}.#{operation.action.to_s.camelcase}.Body".to_sym
|
76
|
+
)
|
74
77
|
AnnotationTypes::CustomT.register(body_type_name, body)
|
75
78
|
|
76
79
|
action_definition[:requestBody] = {
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module RailsParamValidation
|
2
2
|
|
3
3
|
def self.register(type, schema)
|
4
|
-
AnnotationTypes::CustomT.register
|
4
|
+
AnnotationTypes::CustomT.register(
|
5
|
+
Namespace.with_namespace(Namespace.fetch(Namespace.caller_file), type),
|
6
|
+
schema
|
7
|
+
)
|
5
8
|
end
|
6
9
|
|
7
10
|
module AnnotationTypes
|
@@ -72,6 +75,58 @@ end
|
|
72
75
|
end
|
73
76
|
|
74
77
|
module Types
|
78
|
+
class Namespace
|
79
|
+
def self.store(scope, namespace)
|
80
|
+
map[scope] = namespace
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.fetch(scope)
|
84
|
+
path = scope.split('/')
|
85
|
+
|
86
|
+
(path.size - 1).times do
|
87
|
+
key = path.join '/'
|
88
|
+
return map[key] if map.key? key
|
89
|
+
|
90
|
+
path.pop
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.caller_file
|
95
|
+
caller_locations(2, 1)[0].path
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.with_namespace(namespace, type)
|
99
|
+
if namespace
|
100
|
+
path = namespace.to_s.split('.')
|
101
|
+
|
102
|
+
while type.start_with?("_")
|
103
|
+
type = type[1..-1]
|
104
|
+
path.pop
|
105
|
+
end
|
106
|
+
|
107
|
+
"#{path.join(".")}.#{type}".to_sym
|
108
|
+
else
|
109
|
+
type
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class << self
|
114
|
+
protected
|
115
|
+
|
116
|
+
def map
|
117
|
+
@map ||= { '' => nil }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def FileNamespace(namespace)
|
123
|
+
Namespace.store Namespace.caller_file, namespace
|
124
|
+
end
|
125
|
+
|
126
|
+
def DirectoryNamespace(namespace)
|
127
|
+
Namespace.store File.dirname(caller_locations(1, 1)[0].path), namespace
|
128
|
+
end
|
129
|
+
|
75
130
|
def ArrayType(inner_type)
|
76
131
|
AnnotationTypes::ArrayT.new(inner_type)
|
77
132
|
end
|
@@ -85,7 +140,7 @@ module Types
|
|
85
140
|
end
|
86
141
|
|
87
142
|
def Type(type)
|
88
|
-
AnnotationTypes::CustomT.new(type)
|
143
|
+
AnnotationTypes::CustomT.new(Namespace.with_namespace(Namespace.fetch(Namespace.caller_file), type))
|
89
144
|
end
|
90
145
|
end
|
91
146
|
|
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
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oskar Kirmis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-31 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.1.2
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Declarative parameter definition and validation for Rails
|