oas_parser 0.18.2 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/oas_parser/CHANGELOG.md +3 -0
- data/lib/oas_parser/parser.rb +23 -19
- data/lib/oas_parser/pointer.rb +24 -1
- data/lib/oas_parser/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 825c569ee33db4ed6f8b1e666b9bbba45a5440d34d3490074e63f5815414efd8
|
4
|
+
data.tar.gz: 289f26572fa6abbf927305aaba1452d1c15ca6639726bf29768ec5ad12b490ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff8b3c7bcedfd51b38de3a61b0781ea8f64af25238918091b83304c549331aec97ec9714c7daa5c481e37867adb1306529460406e66b21e33fc987772d2b81d8
|
7
|
+
data.tar.gz: 35fe373a593e01a8b26fa8a1e04f0dbc388a6d87475c6523254a54a5de5883adb7ca65c5cc28f566c6c641f5e7a98c21aa9bf0e5db356b561043d875c0efba69
|
data/Gemfile.lock
CHANGED
data/lib/oas_parser/parser.rb
CHANGED
@@ -11,38 +11,38 @@ module OasParser
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def resolve
|
14
|
-
deeply_expand_refs(@content)
|
14
|
+
deeply_expand_refs(@content, nil)
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def deeply_expand_refs(fragment)
|
20
|
-
fragment = expand_refs(fragment)
|
19
|
+
def deeply_expand_refs(fragment, path)
|
20
|
+
fragment, current_path = expand_refs(fragment, path)
|
21
21
|
|
22
22
|
if fragment.is_a?(Hash)
|
23
23
|
fragment.reduce({}) do |hash, (k, v)|
|
24
|
-
hash.merge(k => deeply_expand_refs(v))
|
24
|
+
hash.merge(k => deeply_expand_refs(v, "#{current_path}/#{k}"))
|
25
25
|
end
|
26
26
|
elsif fragment.is_a?(Array)
|
27
|
-
fragment.map { |e| deeply_expand_refs(e) }
|
27
|
+
fragment.map { |e| deeply_expand_refs(e, current_path) }
|
28
28
|
else
|
29
29
|
fragment
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def expand_refs(fragment)
|
34
|
-
|
35
|
-
|
33
|
+
def expand_refs(fragment, current_path)
|
34
|
+
unless fragment.is_a?(Hash) && fragment.key?("$ref")
|
35
|
+
return [fragment, current_path]
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
38
|
+
ref = fragment["$ref"]
|
39
|
+
|
40
|
+
if ref =~ /^#/
|
41
|
+
expand_pointer(ref, current_path)
|
42
|
+
elsif ref =~ /^(http(s)?|\/\/)/
|
43
|
+
expand_url(ref)
|
44
44
|
else
|
45
|
-
|
45
|
+
expand_file(ref)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -59,11 +59,15 @@ module OasParser
|
|
59
59
|
resolved_remote_reference
|
60
60
|
end
|
61
61
|
|
62
|
-
def expand_pointer(ref,
|
62
|
+
def expand_pointer(ref, current_path)
|
63
63
|
pointer = OasParser::Pointer.new(ref)
|
64
|
-
fragment = pointer.resolve(content || @content)
|
65
64
|
|
66
|
-
|
65
|
+
if pointer.circular_reference?(current_path)
|
66
|
+
{ "$ref" => ref }
|
67
|
+
else
|
68
|
+
fragment = pointer.resolve(@content)
|
69
|
+
expand_refs(fragment, current_path + pointer.escaped_pointer)
|
70
|
+
end
|
67
71
|
end
|
68
72
|
|
69
73
|
def expand_url(ref)
|
data/lib/oas_parser/pointer.rb
CHANGED
@@ -12,7 +12,28 @@ module OasParser
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
# Detect circular reference by checking whether the ref exists in current path.
|
16
|
+
#
|
17
|
+
# Example:
|
18
|
+
# components:
|
19
|
+
# schemas:
|
20
|
+
# Pet:
|
21
|
+
# type: object
|
22
|
+
# properties:
|
23
|
+
# name:
|
24
|
+
# type: string
|
25
|
+
# children:
|
26
|
+
# type: array
|
27
|
+
# items: # <--- parsing here
|
28
|
+
# - $ref: '#/components/schemas/Pet'
|
29
|
+
#
|
30
|
+
# path: "/components/schemas/Pet/properties/children/items"
|
31
|
+
# raw_pointer: "#/components/schemas/Pet"
|
32
|
+
#
|
33
|
+
# It'd return true when we're parsing the pet children items where the ref points back to itself.
|
34
|
+
def circular_reference?(path)
|
35
|
+
path.include?("#{escaped_pointer}/")
|
36
|
+
end
|
16
37
|
|
17
38
|
def escaped_pointer
|
18
39
|
if @raw_pointer.start_with?("#")
|
@@ -22,6 +43,8 @@ module OasParser
|
|
22
43
|
end
|
23
44
|
end
|
24
45
|
|
46
|
+
private
|
47
|
+
|
25
48
|
def parse_token(token)
|
26
49
|
if token =~ /\A\d+\z/
|
27
50
|
token.to_i
|
data/lib/oas_parser/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oas_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Butler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -212,6 +212,7 @@ files:
|
|
212
212
|
- bin/console
|
213
213
|
- bin/setup
|
214
214
|
- lib/oas_parser.rb
|
215
|
+
- lib/oas_parser/CHANGELOG.md
|
215
216
|
- lib/oas_parser/abstract_attribute.rb
|
216
217
|
- lib/oas_parser/callback.rb
|
217
218
|
- lib/oas_parser/definition.rb
|