rswag-schema_components 0.3.4 → 0.5.1
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/rswag/schema_components/loader.rb +63 -11
- data/lib/rswag/schema_components/version.rb +1 -1
- data/lib/rswag/schema_components.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 701709c76dfa7a9a7de03e134030eedc51e2851ea4e96eec513a6d4e1cd1887d
|
4
|
+
data.tar.gz: ddeed4c3f4b66dd85a9dcef464176454cbae8b3cd0a5709ee09fcad6a5bbf127
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0decee6e2cdd1fdb59931153f65b1ae171d43a4c0f87ec8abe795e37b38d0fc377fe87fbcf28b7a6d1e457fcdada7a497aa94f5eb1b49727051a189a2ddec1cd
|
7
|
+
data.tar.gz: 37831074fc463141656cb86c9c138b9ff5abba5861442c6a0335c849ccf5da0b04f596b9099db41647fe45426e45d09c59cd7bce63aad022bd7b70fbd01e61d2
|
@@ -40,31 +40,59 @@ module Rswag
|
|
40
40
|
|
41
41
|
definition = definition.merge(title: component_name) if type_allows_title?
|
42
42
|
|
43
|
-
components[component_name] = if component.skip_key_transformation?
|
43
|
+
components[component_name] = if component.skip_key_transformation? || !Rswag::SchemaComponents.camelize_keys
|
44
44
|
definition
|
45
45
|
else
|
46
|
-
definition
|
47
|
-
prefix = key.to_s.start_with?("_") ? "_" : ""
|
48
|
-
|
49
|
-
:"#{prefix}#{key.to_s.delete_prefix("_").camelize(:lower)}"
|
50
|
-
end
|
46
|
+
transform_keys(definition)
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
54
50
|
components
|
55
51
|
end
|
56
52
|
|
53
|
+
private def transform_value(symbolize: true)
|
54
|
+
lambda do |value|
|
55
|
+
prefix = value.to_s.start_with?("_") ? "_" : ""
|
56
|
+
|
57
|
+
new_value = "#{prefix}#{value.to_s.delete_prefix("_").camelize(:lower)}"
|
58
|
+
|
59
|
+
if symbolize
|
60
|
+
new_value = new_value.to_sym
|
61
|
+
end
|
62
|
+
|
63
|
+
new_value
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private def transform_keys(definition)
|
68
|
+
transformed_definition = definition.deep_transform_keys(&transform_value)
|
69
|
+
|
70
|
+
transform_required = proc do |key, value|
|
71
|
+
if key.to_s == "required"
|
72
|
+
value.map! { |v| transform_value(symbolize: false).call(v) }
|
73
|
+
else
|
74
|
+
value
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
transformed_definition.deep_merge!(transformed_definition, &transform_required)
|
79
|
+
end
|
80
|
+
|
57
81
|
private def type_allows_title?
|
58
82
|
type == "schemas"
|
59
83
|
end
|
60
84
|
|
61
85
|
private def load_classes
|
62
|
-
|
63
|
-
|
86
|
+
all_paths = base_paths
|
87
|
+
|
88
|
+
all_paths.flat_map do |base_path|
|
89
|
+
Dir.glob(base_path.join("#{definitions_path}/**/*")).filter_map do |file_path|
|
90
|
+
next if File.directory?(file_path)
|
64
91
|
|
65
|
-
|
66
|
-
|
67
|
-
|
92
|
+
file_path.gsub(base_path.to_s, "") # remove base_path
|
93
|
+
.gsub(".rb", "") # remove extension
|
94
|
+
.camelize.constantize
|
95
|
+
end
|
68
96
|
end
|
69
97
|
end
|
70
98
|
|
@@ -90,6 +118,30 @@ module Rswag
|
|
90
118
|
private def base_path
|
91
119
|
@base_path ||= Rails.root.join(Rswag::SchemaComponents.components_base_path)
|
92
120
|
end
|
121
|
+
|
122
|
+
private def base_paths
|
123
|
+
@base_paths ||= begin
|
124
|
+
paths = [base_path]
|
125
|
+
|
126
|
+
if packs_rails_present?
|
127
|
+
paths.concat(packs_directories.map { |pack_dir| pack_dir.join(Rswag::SchemaComponents.components_base_path) })
|
128
|
+
end
|
129
|
+
|
130
|
+
paths
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
private def packs_rails_present?
|
135
|
+
defined?(Packs)
|
136
|
+
rescue NameError
|
137
|
+
false
|
138
|
+
end
|
139
|
+
|
140
|
+
private def packs_directories
|
141
|
+
return [] unless packs_rails_present?
|
142
|
+
|
143
|
+
Packs.all.map { |pack| Rails.root.join(pack.relative_path) }
|
144
|
+
end
|
93
145
|
end
|
94
146
|
end
|
95
147
|
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.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Klitzke
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-08-21 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rails
|