openapi_contracts 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56248ce2cb1b1a67d4cf1d7390a9815bb9f20a3b9b488e0dd116aa994f8bd9a0
4
- data.tar.gz: a6a8df4841e768c0905bad6699ef0d9295221dad637e5ef8a01c35bb9442a8f0
3
+ metadata.gz: e6c02afb8cd5c3ad005ff169eb4c1294b8de98dd97c4cd643609a8f3a5cc66d5
4
+ data.tar.gz: e8808416c903da9662789d67da35fa6b2f44e9ba7659b7baa675ef5cdabbcd8a
5
5
  SHA512:
6
- metadata.gz: 578b3ef8c71e5a19667e34e2791be7051693d198bf62dfcdaa8b9fc09403cbe54bc12af266c61103eb743a32a8ea0f88552d6eefeecba7ca14d55a3868f0deb8
7
- data.tar.gz: 07c76b46bd842bfb5aa60e9af6cf30a2a45185b682e841183624c222580b3022c7b19239bb2b081a0ae9eedbab365ce78ec55bd4a76e5ba02b9d120fd2a6d853
6
+ metadata.gz: 199fa68a93326277251d413ff5e6c3d2b4718b3345a74cb79f227252a4e741f4cb179f05eaa304b2807b29e64f5510a0c9f5bec817c9373337c68a7f8a1ba8d1
7
+ data.tar.gz: 81c16071342cf8203380e85ced5bf52974231371d269c72ea4d182b472148b4e801c12cc3ca699237643559c1a52dd935f9b984f73c974e51002061da8b3dfa3
@@ -10,13 +10,14 @@ module OpenapiContracts
10
10
  end
11
11
  end
12
12
 
13
- def self.parse(root, pathname)
14
- new(root, pathname).call
13
+ def self.parse(rootfile, pathname)
14
+ new(rootfile, pathname).call
15
15
  end
16
16
 
17
- def initialize(root, pathname)
18
- @root = root
19
- @pathname = pathname.relative? ? root.join(pathname) : pathname
17
+ def initialize(rootfile, pathname)
18
+ @root = rootfile.parent
19
+ @rootfile = rootfile
20
+ @pathname = pathname.relative? ? @root.join(pathname) : pathname
20
21
  end
21
22
 
22
23
  def call
@@ -57,11 +58,11 @@ module OpenapiContracts
57
58
  def transform_pointer(key, target)
58
59
  if %r{^#/(?<pointer>.*)} =~ target
59
60
  # A JSON Pointer
60
- {key => "#/#{@pathname.relative_path_from(@root).sub_ext('').join(pointer)}"}
61
+ {key => generate_absolute_pointer(pointer)}
61
62
  elsif %r{^(?<relpath>[^#]+)(?:#/(?<pointer>.*))?} =~ target
62
63
  if relpath.start_with?('paths') # path description file pointer
63
64
  # Inline the file contents
64
- self.class.parse(@root, Pathname(relpath)).data
65
+ self.class.parse(@rootfile, Pathname(relpath)).data
65
66
  else # A file pointer with potential JSON sub-pointer
66
67
  tgt = @pathname.parent.relative_path_from(@root).join(relpath).sub_ext('')
67
68
  tgt = tgt.join(pointer) if pointer
@@ -71,5 +72,14 @@ module OpenapiContracts
71
72
  {key => target}
72
73
  end
73
74
  end
75
+
76
+ # A JSON pointer to the currently parsed file as seen from the root openapi file
77
+ def generate_absolute_pointer(json_pointer)
78
+ if @rootfile == @pathname
79
+ "#/#{json_pointer}"
80
+ else
81
+ "#/#{@pathname.relative_path_from(@root).sub_ext('').join(json_pointer)}"
82
+ end
83
+ end
74
84
  end
75
85
  end
@@ -1,27 +1,27 @@
1
1
  module OpenapiContracts
2
2
  class Doc::Parser
3
3
  def self.call(dir, filename)
4
- new(dir).parse(filename)
4
+ new(dir.join(filename)).parse
5
5
  end
6
6
 
7
- def initialize(dir)
8
- @dir = dir
7
+ def initialize(rootfile)
8
+ @rootfile = rootfile
9
9
  end
10
10
 
11
- def parse(path)
12
- abs_path = @dir.join(path)
13
- file = Doc::FileParser.parse(@dir, abs_path)
11
+ def parse
12
+ file = Doc::FileParser.parse(@rootfile, @rootfile)
14
13
  data = file.data
15
14
  data.deep_merge! merge_components
16
15
  nullable_to_type!(data)
16
+ # debugger
17
17
  end
18
18
 
19
19
  private
20
20
 
21
21
  def merge_components
22
22
  data = {}
23
- Dir[File.expand_path('components/**/*.yaml', @dir)].each do |file|
24
- result = Doc::FileParser.parse(@dir, Pathname(file))
23
+ Dir[File.expand_path('components/**/*.yaml', @rootfile.parent)].each do |file|
24
+ result = Doc::FileParser.parse(@rootfile, Pathname(file))
25
25
  data.deep_merge!(result.to_mergable_hash)
26
26
  end
27
27
  data
@@ -2,7 +2,8 @@ module OpenapiContracts
2
2
  class Doc::Path
3
3
  def initialize(schema)
4
4
  @schema = schema
5
- @methods = @schema.to_h do |method, _|
5
+
6
+ @methods = (known_http_methods & @schema.keys).to_h do |method|
6
7
  [method, Doc::Method.new(@schema.navigate(method))]
7
8
  end
8
9
  end
@@ -14,5 +15,12 @@ module OpenapiContracts
14
15
  def with_method(method)
15
16
  @methods[method]
16
17
  end
18
+
19
+ private
20
+
21
+ def known_http_methods
22
+ # https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
23
+ %w(get head post put delete connect options trace patch).freeze
24
+ end
17
25
  end
18
26
  end
@@ -26,7 +26,7 @@ module OpenapiContracts
26
26
  pointer.map { |p| p.gsub('/', '~1') }.join('/').then { |s| "#/#{s}" }
27
27
  end
28
28
 
29
- delegate :dig, :fetch, :key?, :[], :to_h, to: :as_h
29
+ delegate :dig, :fetch, :keys, :key?, :[], :to_h, to: :as_h
30
30
 
31
31
  def at_pointer(pointer)
32
32
  self.class.new(raw, pointer)
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.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mkon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-31 00:00:00.000000000 Z
11
+ date: 2023-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - '='
94
94
  - !ruby/object:Gem::Version
95
- version: 1.51.0
95
+ version: 1.52.0
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: 1.51.0
102
+ version: 1.52.0
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rubocop-rspec
105
105
  requirement: !ruby/object:Gem::Requirement