Skip to content

Commit d70d2bd

Browse files
committed
🚧 chore: add strategic merge patch
Previous attempts prove to be limited because their are too generaliste. introducing a new patch finishing to reduce divengence between implementations
1 parent b9dbd96 commit d70d2bd

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

hacks/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ for typescript-axios.
3838
- nodate: remove date format from strings
3939
- nooneof: substitube oneOf for the first type defined
4040
- noproperties-array: inflate array's items definition
41+
- patch: apply strategic merge patch in post-process. Should be last resort

hacks/patch.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
opt.on('--nodate') { || options[:nodate] = true }
1010
opt.on('--nooneof') { || options[:nooneof] = true }
1111
opt.on('--noproperties-array') { || options[:nopropertiesarray] = true }
12+
opt.on('--patch FILE') { |o| options[:patch] = o }
1213
opt.on('--input FILE') { |o| options[:input] = o }
1314
end.parse!
1415

@@ -101,4 +102,21 @@ def patch_no_poperties_array(prop_info)
101102
end
102103
end
103104

105+
if options.key?(:patch) then
106+
# As a last ressource, patch openapi with strategic merge patch
107+
patch = Psych.load_file options[:patch], permitted_classes: [Time]
108+
109+
def strtegic_merge(base, p)
110+
base.merge(p) do |key, old_val, new_val|
111+
if old_val.is_a?(Hash) and new_val.is_a?(Hash) then
112+
strtegic_merge(old_val, new_val)
113+
else
114+
new_val
115+
end
116+
end
117+
end
118+
119+
api = strtegic_merge(api, patch)
120+
end
121+
104122
puts Psych.dump(api)

0 commit comments

Comments
 (0)