rails-param-validation 0.2.3 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4a98d65517bb634880f15f8646ee1645a60c00a962c7c604df80c9ead49404f
4
- data.tar.gz: 7e755c2e7011fa1c848c1f4cf59ca93232a8829ba081c11b859707e652ed3a9f
3
+ metadata.gz: 1e81185301762be6703608dfc575c27813c49fde9969057c0b821c7cc78f7680
4
+ data.tar.gz: 5c3c75f3d2a8e6275d1c794540d972e62b13ada2592a5602ca71bb80794d6f05
5
5
  SHA512:
6
- metadata.gz: ceb39335b93f488396532b5317a7cc48ddd633e795417bb30b4c628f790778864024ce83e67affb2a4e91713b9e8f2f8336bdfb3d4998714fbf3ca1df6112518
7
- data.tar.gz: 811e141a19bcafadc2a0270620ad844ae104249b45dd9581b0d083694b48874914dba256a304842a4d60fbbc5316ab7013a35027c693166b04ce2c07caeb39e4
6
+ metadata.gz: 1af2e48e2ef3d6af489e009177839378b5e19b8817a456a9cb1e399e525b2a974d52ed1986a321c44035248c527d8ef1b7711de0e175252791a12567a8bd98da
7
+ data.tar.gz: b4528b9e92d0c7079cced511255760766771ba6b6f9e5f013d8f1049bdf1fce6f10f86750760bae7ebb12d53ce66b027d18d4228c7dd953d5f1e6fa70af60979
@@ -1,7 +1,7 @@
1
1
  module RailsParamValidation
2
2
 
3
3
  class ActionDefinition
4
- attr_reader :params, :request_body_type, :paths, :responses, :controller, :action
4
+ attr_reader :params, :request_body_type, :paths, :responses, :controller, :action, :security
5
5
  attr_accessor :description
6
6
 
7
7
  def initialize
@@ -11,6 +11,8 @@ module RailsParamValidation
11
11
  @description = ''
12
12
  @request_body_type = RailsParamValidation.config.default_body_content_type if defined?(Rails)
13
13
  @responses = {}
14
+ @flags = {}
15
+ @security = []
14
16
  end
15
17
 
16
18
  def store_origin!(controller, action)
@@ -38,6 +40,18 @@ module RailsParamValidation
38
40
  }
39
41
  end
40
42
 
43
+ def add_security(security)
44
+ @security.push(security.is_a?(Hash) ? security : { security => [] })
45
+ end
46
+
47
+ def add_flag(name, value)
48
+ @flags[name.to_sym] = value
49
+ end
50
+
51
+ def flag(name, default)
52
+ @flags.fetch(name, default)
53
+ end
54
+
41
55
  def add_response(status, schema, description)
42
56
  @responses[status] = {
43
57
  schema: schema,
@@ -1,7 +1,7 @@
1
1
  module RailsParamValidation
2
2
 
3
3
  class OpenApiMetaConfig
4
- attr_accessor :title, :version, :url, :description, :file_path
4
+ attr_accessor :title, :version, :url, :description, :file_path, :security_schemes, :skip_format_endpoints
5
5
 
6
6
  def initialize
7
7
  app_class = Rails.application.class
@@ -11,6 +11,8 @@ module RailsParamValidation
11
11
  self.version = '1.0'
12
12
  self.description = "#{app_name(app_class)} application"
13
13
  self.file_path = Rails.root.join("openapi.yaml").to_s
14
+ self.security_schemes = {}
15
+ self.skip_format_endpoints = true
14
16
  end
15
17
 
16
18
  private
@@ -27,6 +29,8 @@ module RailsParamValidation
27
29
  attr_accessor :use_validator_caching
28
30
  attr_accessor :raise_on_missing_annotation
29
31
  attr_accessor :default_body_content_type
32
+ attr_accessor :default_action_flags
33
+ attr_accessor :post_action_definition_hook
30
34
  attr_reader :openapi
31
35
 
32
36
  def initialize
@@ -35,6 +39,8 @@ module RailsParamValidation
35
39
  @use_validator_caching = Rails.env.production?
36
40
  @raise_on_missing_annotation = true
37
41
  @default_body_content_type = 'application/json'
42
+ @default_action_flags = {}
43
+ @post_action_definition_hook = ->(_action_definition) {}
38
44
  end
39
45
  end
40
46
 
@@ -22,6 +22,7 @@ module RailsParamValidation
22
22
  method_name = name.to_sym
23
23
 
24
24
  @param_definition.store_origin! class_name, method_name
25
+ RailsParamValidation.config.post_action_definition_hook.call(@param_definition)
25
26
  @param_definition.finalize! class_name, method_name
26
27
 
27
28
  AnnotationManager.instance.annotate_method! self, name, :param_definition, @param_definition
@@ -84,12 +85,21 @@ module RailsParamValidation
84
85
  param_definition.add_response status, schema, description
85
86
  end
86
87
 
87
- def action(description = nil)
88
+ def flag(name, value, _comment = nil)
89
+ @param_definition.add_flag name, value
90
+ end
91
+
92
+ def security_hint(security)
93
+ @param_definition.add_security(security)
94
+ end
95
+
96
+ def action(description = nil, flags = RailsParamValidation.config.default_action_flags)
88
97
  @param_definition = ActionDefinition.new
89
98
  @param_definition.description = description
99
+ flags.each { |name, value| @param_definition.add_flag name, value }
90
100
 
91
101
  yield
92
102
  end
93
103
  end
94
104
  end
95
- end
105
+ end
@@ -51,6 +51,7 @@ module RailsParamValidation
51
51
  operationId: "#{route[:method].downcase}#{route[:path].split(/[^a-zA-Z0-9]+/).map(&:downcase).map(&:capitalize).join}",
52
52
  tags: [operation.controller],
53
53
  parameters: parameters,
54
+ security: operation.security,
54
55
  responses: operation.responses.map do |status, values|
55
56
  [
56
57
  status.to_s,
@@ -90,6 +91,9 @@ module RailsParamValidation
90
91
  object[:components][:schemas][name] = ValidatorFactory.create(AnnotationTypes::CustomT.registered(name)).to_openapi
91
92
  end
92
93
 
94
+ if RailsParamValidation.openapi.security_schemes.any?
95
+ object[:components][:securitySchemes] = RailsParamValidation.openapi.security_schemes
96
+ end
93
97
  stringify_values object
94
98
  end
95
99
 
@@ -29,7 +29,9 @@ module RailsParamValidation
29
29
  Rails.application.routes.routes.each do |route|
30
30
  if route.defaults[:controller] == controller && route.defaults[:action] == action
31
31
  Formatter.new.accept(route.path.ast, [""]).each do |path|
32
- routes.push(path: path, method: route.verb)
32
+ if !RailsParamValidation.openapi.skip_format_endpoints || !path.end_with?('.{format}')
33
+ routes.push(path: path, method: route.verb)
34
+ end
33
35
  end
34
36
  end
35
37
  end
@@ -1,3 +1,3 @@
1
1
  module RailsParamValidation
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.3
4
+ version: 0.3.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-23 00:00:00.000000000 Z
11
+ date: 2020-07-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Declarative parameter definition and validation for Rails
14
14
  email: