openapi_contracts 0.2.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/openapi_contracts/doc/parser.rb +28 -11
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f218118990cd1c4d1d2933bcb42a84a84492226a1a075d2cb92a5acd026b3478
|
4
|
+
data.tar.gz: 072bf7fd56d4a22adacb31706e8773888588e3e466b9783653065a335de4a063
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54e760ebff2c63b357bad2f47b1ad741405fbe23997af447079361e377cda3419d7befa4717cc193e0f7f11fe56ce719dc93c3dc198e70b9257b30b3d8e3e1db
|
7
|
+
data.tar.gz: b706d606ec874409f5b1cdae4dd3b166b036cbc009f4d288f423cfae870c4db8d58e5751ebc38607e7b1349b189c4441bb78256d349a9739653966c7490b751c
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ First parse your api documentation:
|
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
# This must point to the folder where the "openapi.yaml" file is
|
19
|
-
$doc = OpenapiContracts::Doc.parse(Rails.root.join('spec
|
19
|
+
$doc = OpenapiContracts::Doc.parse(Rails.root.join('spec/fixtures/openapi/api-docs/openapi'))
|
20
20
|
```
|
21
21
|
|
22
22
|
Ideally you do this once in a RSpec `before(:suite)` hook.
|
@@ -12,14 +12,15 @@ module OpenapiContracts
|
|
12
12
|
abs_path = @dir.join(path)
|
13
13
|
data = parse_file(abs_path, translate: false)
|
14
14
|
data.deep_merge! merge_components
|
15
|
-
join_partials(abs_path.dirname, data)
|
15
|
+
data = join_partials(abs_path.dirname, data)
|
16
|
+
nullable_to_type!(data)
|
16
17
|
end
|
17
18
|
|
18
19
|
private
|
19
20
|
|
20
21
|
def parse_file(path, translate: true)
|
21
22
|
schema = YAML.safe_load(File.read(path))
|
22
|
-
translate ? translate_paths(schema, Pathname(path).parent) : schema
|
23
|
+
translate ? translate_paths!(schema, Pathname(path).parent) : schema
|
23
24
|
end
|
24
25
|
|
25
26
|
def join_partials(cwd, data)
|
@@ -34,10 +35,23 @@ module OpenapiContracts
|
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
38
|
+
def nullable_to_type!(object)
|
39
|
+
case object
|
40
|
+
when Hash
|
41
|
+
if object['type'] && object['nullable']
|
42
|
+
object['type'] = [object['type'], 'null']
|
43
|
+
object.delete 'nullable'
|
44
|
+
else
|
45
|
+
object.each_value { |o| nullable_to_type! o }
|
46
|
+
end
|
47
|
+
when Array
|
48
|
+
object.each { |o| nullable_to_type! o }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
37
52
|
def merge_components
|
38
53
|
data = {}
|
39
54
|
Dir[File.expand_path('components/**/*.yaml', @dir)].each do |file|
|
40
|
-
# pn = Pathname(file).relative_path_from(@dir)
|
41
55
|
pointer = json_pointer(Pathname(file)).split('/')
|
42
56
|
i = 0
|
43
57
|
pointer.reduce(data) do |h, p|
|
@@ -53,14 +67,17 @@ module OpenapiContracts
|
|
53
67
|
data
|
54
68
|
end
|
55
69
|
|
56
|
-
def translate_paths(data, cwd)
|
57
|
-
data
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
70
|
+
def translate_paths!(data, cwd)
|
71
|
+
case data
|
72
|
+
when Array
|
73
|
+
data.each { |v| translate_paths!(v, cwd) }
|
74
|
+
when Hash
|
75
|
+
data.each_pair do |k, v|
|
76
|
+
if k == '$ref' && v !~ %r{^#/}
|
77
|
+
v.replace json_pointer(cwd.join(v), '#/')
|
78
|
+
else
|
79
|
+
translate_paths!(v, cwd)
|
80
|
+
end
|
64
81
|
end
|
65
82
|
end
|
66
83
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openapi_contracts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mkon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -78,28 +78,28 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - '='
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 1.29.
|
81
|
+
version: 1.29.1
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - '='
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 1.29.
|
88
|
+
version: 1.29.1
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: rubocop-rspec
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - '='
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: 2.
|
95
|
+
version: 2.11.1
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - '='
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: 2.
|
102
|
+
version: 2.11.1
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: simplecov
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
146
|
version: '2.7'
|
147
147
|
- - "<"
|
148
148
|
- !ruby/object:Gem::Version
|
149
|
-
version: '3.
|
149
|
+
version: '3.3'
|
150
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
152
|
- - ">="
|