openapi-sourcetools 0.9.0 → 0.9.2

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: 44ff7d64b4781fdfbab07060f6faa294a8092e342530e6cde786e50ff8f69db1
4
- data.tar.gz: 893e593407c4734e67c83bffe77a67bb55b2ecef3970620a416580fd33109437
3
+ metadata.gz: 625fca7f208b4a1e4c041265a1b5aba0d0685bbda6dcdd831af5db701aff4de0
4
+ data.tar.gz: bfe98b2ef3fa42ca2edccdf7b57eda9d653637e23a6b6325e41297e00100e1b6
5
5
  SHA512:
6
- metadata.gz: 741c12063a6d5df5d090f26b80c60a7810083537076573cb10f9ba5a3ca3afc8109ab6faa305707139c881a7efa1f478d7d0de562db67b44f93c0329ae8263e4
7
- data.tar.gz: 9e1c2bc87442258d75517beb13f99c1e0b210b7074ee622db8057e1e4ebf17c253538ba52b893b0f148baa21188a306976a9783d778e92dd769caee6eb84aef6
6
+ metadata.gz: 7895833d61f1954c4d6b056e2b350c72d767c7ec031222bcec9f8aa2820836eced6e5432f14465f567967bce674006e699bc65180d73951a1ff63b7d40c5fc57
7
+ data.tar.gz: b86546e0d0cf07d19ba082e43f29b4f0c35bef6d05f6e678695f7d821bf38e1e761eaa95ecf10a7c0a00e0a41710fdf088eba13b8c3bd9f4b46a7bac7db49f49
@@ -48,10 +48,13 @@ def replace_inlines(obj, components, top_level_name = nil)
48
48
  when 'array'
49
49
  return false unless replace_inlines(obj['items'], components)
50
50
  when 'object'
51
- props = obj.fetch('properties', {})
52
- props.keys.sort!.each do |name|
53
- return false unless replace_inlines(props[name], components)
51
+ %w[properties patternProperties].each do |prop_name|
52
+ props = obj.fetch(prop_name, {})
53
+ props.keys.sort!.each do |name|
54
+ return false unless replace_inlines(props[name], components)
55
+ end
54
56
  end
57
+ return false unless replace_inlines(obj['additionalProperties'], components)
55
58
  end
56
59
  r = components.ref_string(top_level_name) || components.reference(obj)
57
60
  components.store_anchor(obj, r)
data/bin/openapi-merge CHANGED
@@ -6,9 +6,9 @@
6
6
 
7
7
  require_relative '../lib/openapi/sourcetools/common'
8
8
  require 'optparse'
9
- require 'set'
10
9
  include OpenAPISourceTools
11
10
 
11
+
12
12
  def raise_se(message)
13
13
  raise StandardError, message
14
14
  end
@@ -26,6 +26,14 @@ def too_deep(path, max_depths)
26
26
  max_depths.fetch(path.first) <= path.size
27
27
  end
28
28
 
29
+ def add_missing(existing, incoming, field)
30
+ incoming.each do |t|
31
+ tv = t[field]
32
+ next if tv.nil?
33
+ existing.push(t) if existing.index { |e| e.key?(field) && e[field] == tv }.nil?
34
+ end
35
+ end
36
+
29
37
  def add_undefined(merged, incoming, filename, path, max_depths)
30
38
  incoming.each_pair do |key, value|
31
39
  unless merged.key? key
@@ -40,9 +48,11 @@ def add_undefined(merged, incoming, filename, path, max_depths)
40
48
  add_undefined(m, value, filename, path, max_depths)
41
49
  path.pop
42
50
  elsif m.is_a? Array
43
- value.each do |v|
44
- next if m.include? v
45
- m.push v
51
+ case key
52
+ when 'tags' then add_missing(m, value, 'name')
53
+ when 'servers' then add_missing(m, value, 'url')
54
+ else
55
+ value.each { |v| m.push(v) unless m.include?(v) }
46
56
  end
47
57
  else
48
58
  raise_se "Re-definition of #{key} #{path_combo(path)} in #{filename}"
@@ -65,10 +75,10 @@ def gather_refs(doc, found)
65
75
  end
66
76
 
67
77
  def has_refd_anchor(item, refs)
68
- return !((item.index { |v| has_refd_anchor(v, refs) }).nil?) if item.is_a?(Array)
78
+ return !item.index { |v| has_refd_anchor(v, refs) }.nil? if item.is_a?(Array)
69
79
  return false unless item.is_a?(Hash)
70
- return true if refs.member?('#' + item.fetch('$anchor', ''))
71
- !((item.values.index { |v| has_refd_anchor(v, refs) }).nil?)
80
+ return true if refs.member?("##{item.fetch('$anchor', '')}")
81
+ !item.values.index { |v| has_refd_anchor(v, refs) }.nil?
72
82
  end
73
83
 
74
84
  def prune(merged)
@@ -83,7 +93,7 @@ def prune(merged)
83
93
  end
84
94
  # Add schema ref for all schemas that have referenced anchor somewhere.
85
95
  (merged.dig(*%w[components schemas]) || {}).each do |name, schema|
86
- refs.add("#/components/Schemas/#{name}") if has_refd_anchor(schema, refs)
96
+ refs.add("#/components/schemas/#{name}") if has_refd_anchor(schema, refs)
87
97
  end
88
98
  used = {}
89
99
  all = merged.fetch('components', {})
@@ -21,6 +21,13 @@ def find_patterns(doc, pmm)
21
21
  pmm[key(doc)] = item
22
22
  return
23
23
  end
24
+ pps = doc['patternProperties']
25
+ unless pps.nil?
26
+ pps.keys.sort!.each do |pat|
27
+ item = { 'pattern' => pat }
28
+ pmm[key(item)] = item
29
+ end
30
+ end
24
31
  doc = doc.values
25
32
  end
26
33
  doc.each { |v| find_patterns(v, pmm) } if doc.is_a?(Array)
@@ -5,7 +5,7 @@
5
5
 
6
6
  module OpenAPISourceTools
7
7
  NAME = 'openapi-sourcetools'
8
- VERSION = '0.9.0'
8
+ VERSION = '0.9.2'
9
9
 
10
10
  def self.info(separator = ': ')
11
11
  "#{NAME}#{separator}#{VERSION}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi-sourcetools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismo Kärkkäinen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-15 00:00:00.000000000 Z
11
+ date: 2025-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge