rswag-schema_components 0.3.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c98e715a9103f4adf15c3abe62868975e65135f4530396a4afbf0246919a050a
4
- data.tar.gz: 030662f0bd7528c69be66d73fc4d1b29dd8c9581d94478e6d6a780eb7212d6c7
3
+ metadata.gz: cdbe6ec79d6079d3ff7cc0140aeff7f7b1601d28cc2c6162cc02ce93bdac955a
4
+ data.tar.gz: 3986c07499d385764bd05f3e9f9676f55419ca253c034dc9a663278e472bb20b
5
5
  SHA512:
6
- metadata.gz: 69ca24eac0c1d4b87b854b73794dbd2e9ab52a6dd710cfa2c1d8f5ffada89a96584faf00e6d2a1a060e70ce76049fc18cb0aea0f51526e94883549286f824a82
7
- data.tar.gz: f7e6518945baa9515940ec16b5957a755d0cd5bdd4bd31068cb230042102002eb9affeecce883254b19ff820280e34f39d39c582d44e705702d57a050d1d589f
6
+ metadata.gz: eca7f4ff84bc270001afe84a2881c701eb712892753f4aecbad14173d0368c7d61004288e2bdb6d9cc7db5e5094be593b7c7a9f664528b17402a5be0c6a7515e
7
+ data.tar.gz: 5f3883a422fd082716bf8c643d37266e973281e97a4428e953ef6a42230d69fe9be1f3910f498d7be25cf7071eb5bb233eabbf89181bc1bc5fe41b2e5d3438b6
@@ -7,7 +7,7 @@ module Rswag
7
7
 
8
8
  included do
9
9
  class << self
10
- attr_accessor :schema_value, :schema_hidden_value
10
+ attr_accessor :schema_value, :schema_hidden_value, :skip_key_transformation_value
11
11
 
12
12
  def schema(schema_definition)
13
13
  self.schema_value = if superclass.respond_to?(:schema_value)
@@ -21,6 +21,10 @@ module Rswag
21
21
  def schema_hidden(flag = false)
22
22
  self.schema_hidden_value = flag
23
23
  end
24
+
25
+ def skip_key_transformation(flag = false)
26
+ self.skip_key_transformation_value = flag
27
+ end
24
28
  end
25
29
 
26
30
  def to_schema
@@ -30,6 +34,10 @@ module Rswag
30
34
  def hidden?
31
35
  self.class.schema_hidden_value
32
36
  end
37
+
38
+ def skip_key_transformation?
39
+ self.class.skip_key_transformation_value
40
+ end
33
41
  end
34
42
  end
35
43
  end
@@ -40,10 +40,14 @@ module Rswag
40
40
 
41
41
  definition = definition.merge(title: component_name) if type_allows_title?
42
42
 
43
- components[component_name] = definition.deep_transform_keys do |key|
44
- prefix = key.to_s.start_with?("_") ? "_" : ""
45
-
46
- "#{prefix}#{key.to_s.delete_prefix("_").camelize(:lower)}".to_sym
43
+ components[component_name] = if component.skip_key_transformation?
44
+ definition
45
+ else
46
+ definition.deep_transform_keys do |key|
47
+ prefix = key.to_s.start_with?("_") ? "_" : ""
48
+
49
+ :"#{prefix}#{key.to_s.delete_prefix("_").camelize(:lower)}"
50
+ end
47
51
  end
48
52
  end
49
53
 
@@ -55,12 +59,16 @@ module Rswag
55
59
  end
56
60
 
57
61
  private def load_classes
58
- Dir.glob(base_path.join("#{definitions_path}/**/*")).filter_map do |file_path|
59
- next if File.directory?(file_path)
62
+ all_paths = base_paths
63
+
64
+ all_paths.flat_map do |base_path|
65
+ Dir.glob(base_path.join("#{definitions_path}/**/*")).filter_map do |file_path|
66
+ next if File.directory?(file_path)
60
67
 
61
- file_path.gsub(base_path.to_s, "") # remove base_path
62
- .gsub(".rb", "") # remove extension
63
- .camelize.constantize
68
+ file_path.gsub(base_path.to_s, "") # remove base_path
69
+ .gsub(".rb", "") # remove extension
70
+ .camelize.constantize
71
+ end
64
72
  end
65
73
  end
66
74
 
@@ -86,6 +94,30 @@ module Rswag
86
94
  private def base_path
87
95
  @base_path ||= Rails.root.join(Rswag::SchemaComponents.components_base_path)
88
96
  end
97
+
98
+ private def base_paths
99
+ @base_paths ||= begin
100
+ paths = [base_path]
101
+
102
+ if packs_rails_present?
103
+ paths.concat(packs_directories.map { |pack_dir| pack_dir.join(Rswag::SchemaComponents.components_base_path) })
104
+ end
105
+
106
+ paths
107
+ end
108
+ end
109
+
110
+ private def packs_rails_present?
111
+ defined?(Packs)
112
+ rescue NameError
113
+ false
114
+ end
115
+
116
+ private def packs_directories
117
+ return [] unless packs_rails_present?
118
+
119
+ Packs.all.map { |pack| Rails.root.join(pack.relative_path) }
120
+ end
89
121
  end
90
122
  end
91
123
  end
@@ -1,5 +1,5 @@
1
1
  module Rswag
2
2
  module SchemaComponents
3
- VERSION = "0.3.3"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rswag-schema_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Klitzke
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-07-29 00:00:00.000000000 Z
10
+ date: 2025-08-21 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails