openapi3_parser 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +2 -4
  4. data/.travis.yml +11 -0
  5. data/CHANGELOG.md +13 -0
  6. data/README.md +4 -1
  7. data/TODO.md +1 -1
  8. data/lib/openapi3_parser.rb +2 -3
  9. data/lib/openapi3_parser/array_sentence.rb +1 -0
  10. data/lib/openapi3_parser/document.rb +2 -1
  11. data/lib/openapi3_parser/node/array.rb +1 -1
  12. data/lib/openapi3_parser/node/context.rb +23 -0
  13. data/lib/openapi3_parser/node/map.rb +1 -1
  14. data/lib/openapi3_parser/node/object.rb +1 -0
  15. data/lib/openapi3_parser/node/operation.rb +8 -0
  16. data/lib/openapi3_parser/node/path_item.rb +8 -0
  17. data/lib/openapi3_parser/node/placeholder.rb +8 -5
  18. data/lib/openapi3_parser/node/schema.rb +3 -2
  19. data/lib/openapi3_parser/node_factory.rb +1 -1
  20. data/lib/openapi3_parser/node_factory/array.rb +34 -26
  21. data/lib/openapi3_parser/node_factory/context.rb +9 -2
  22. data/lib/openapi3_parser/node_factory/discriminator.rb +2 -0
  23. data/lib/openapi3_parser/node_factory/field.rb +2 -0
  24. data/lib/openapi3_parser/node_factory/fields/reference.rb +1 -0
  25. data/lib/openapi3_parser/node_factory/map.rb +6 -4
  26. data/lib/openapi3_parser/node_factory/media_type.rb +1 -0
  27. data/lib/openapi3_parser/node_factory/object.rb +4 -1
  28. data/lib/openapi3_parser/node_factory/object_factory/dsl.rb +1 -1
  29. data/lib/openapi3_parser/node_factory/object_factory/field_config.rb +1 -0
  30. data/lib/openapi3_parser/node_factory/object_factory/node_builder.rb +1 -0
  31. data/lib/openapi3_parser/node_factory/object_factory/validator.rb +6 -4
  32. data/lib/openapi3_parser/node_factory/openapi.rb +2 -0
  33. data/lib/openapi3_parser/node_factory/operation.rb +11 -0
  34. data/lib/openapi3_parser/node_factory/parameter.rb +2 -0
  35. data/lib/openapi3_parser/node_factory/parameter_like.rb +1 -0
  36. data/lib/openapi3_parser/node_factory/path_item.rb +27 -5
  37. data/lib/openapi3_parser/node_factory/paths.rb +1 -1
  38. data/lib/openapi3_parser/node_factory/response.rb +1 -0
  39. data/lib/openapi3_parser/node_factory/responses.rb +1 -1
  40. data/lib/openapi3_parser/node_factory/schema.rb +3 -0
  41. data/lib/openapi3_parser/node_factory/server_variable.rb +1 -0
  42. data/lib/openapi3_parser/node_factory/type_checker.rb +6 -0
  43. data/lib/openapi3_parser/source.rb +2 -0
  44. data/lib/openapi3_parser/source/location.rb +6 -0
  45. data/lib/openapi3_parser/source/pointer.rb +5 -0
  46. data/lib/openapi3_parser/source_input.rb +2 -0
  47. data/lib/openapi3_parser/source_input/file.rb +2 -0
  48. data/lib/openapi3_parser/source_input/raw.rb +3 -0
  49. data/lib/openapi3_parser/source_input/resolve_next.rb +1 -0
  50. data/lib/openapi3_parser/source_input/string_parser.rb +3 -2
  51. data/lib/openapi3_parser/source_input/url.rb +2 -0
  52. data/lib/openapi3_parser/validation/error.rb +2 -0
  53. data/lib/openapi3_parser/validators/component_keys.rb +1 -1
  54. data/lib/openapi3_parser/validators/duplicate_parameters.rb +1 -0
  55. data/lib/openapi3_parser/validators/email.rb +1 -1
  56. data/lib/openapi3_parser/validators/media_type.rb +1 -1
  57. data/lib/openapi3_parser/validators/mutually_exclusive_fields.rb +2 -2
  58. data/lib/openapi3_parser/validators/reference.rb +2 -0
  59. data/lib/openapi3_parser/validators/required_fields.rb +2 -2
  60. data/lib/openapi3_parser/validators/unexpected_fields.rb +3 -2
  61. data/lib/openapi3_parser/version.rb +1 -1
  62. data/openapi3_parser.gemspec +9 -7
  63. metadata +44 -16
@@ -39,6 +39,7 @@ module Openapi3Parser
39
39
  # @return [Boolean]
40
40
  def ==(other)
41
41
  return false unless other.instance_of?(self.class)
42
+
42
43
  path == other.path &&
43
44
  working_directory == other.working_directory
44
45
  end
@@ -66,6 +67,7 @@ module Openapi3Parser
66
67
  end
67
68
 
68
69
  return path unless other_path
70
+
69
71
  other_path ? relative_path(other_path, path) : path
70
72
  end
71
73
 
@@ -44,6 +44,7 @@ module Openapi3Parser
44
44
  # @return [Boolean]
45
45
  def ==(other)
46
46
  return false unless other.instance_of?(self.class)
47
+
47
48
  raw_input == other.raw_input &&
48
49
  base_url == other.base_url &&
49
50
  working_directory == other.working_directory
@@ -72,6 +73,7 @@ module Openapi3Parser
72
73
 
73
74
  def parse_contents
74
75
  return raw_input if raw_input.respond_to?(:keys)
76
+
75
77
  StringParser.call(
76
78
  input_to_string(raw_input),
77
79
  raw_input.respond_to?(:path) ? ::File.basename(raw_input.path) : nil
@@ -81,6 +83,7 @@ module Openapi3Parser
81
83
  def input_to_string(input)
82
84
  return input.read if input.respond_to?(:read)
83
85
  return input.to_s if input.respond_to?(:to_s)
86
+
84
87
  input
85
88
  end
86
89
  end
@@ -30,6 +30,7 @@ module Openapi3Parser
30
30
 
31
31
  def source_input
32
32
  return current_source_input if reference.only_fragment?
33
+
33
34
  if reference.absolute?
34
35
  SourceInput::Url.new(reference.resource_uri)
35
36
  else
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "yaml"
3
+ require "psych"
4
4
  require "json"
5
5
 
6
6
  module Openapi3Parser
@@ -27,6 +27,7 @@ module Openapi3Parser
27
27
 
28
28
  def json?
29
29
  return false if filename && ::File.extname(filename) == ".yaml"
30
+
30
31
  json_filename = filename && ::File.extname(filename) == ".json"
31
32
  json_filename || input.strip[0] == "{"
32
33
  end
@@ -36,7 +37,7 @@ module Openapi3Parser
36
37
  end
37
38
 
38
39
  def parse_yaml
39
- YAML.safe_load(input, [Date, Time], [], true)
40
+ Psych.safe_load(input, permitted_classes: [Date, Time], aliases: true)
40
41
  end
41
42
  end
42
43
  end
@@ -32,6 +32,7 @@ module Openapi3Parser
32
32
  # @return [Boolean]
33
33
  def ==(other)
34
34
  return false unless other.instance_of?(self.class)
35
+
35
36
  [request_url, resolved_url].include?(other.request_url) ||
36
37
  [request_url, resolved_url].include?(other.resolved_url)
37
38
  end
@@ -89,6 +90,7 @@ module Openapi3Parser
89
90
 
90
91
  def call
91
92
  return to_uri.to_s if different_hosts?
93
+
92
94
  relative_path
93
95
  end
94
96
 
@@ -35,6 +35,7 @@ module Openapi3Parser
35
35
  def for_type
36
36
  return unless factory_class
37
37
  return "(anonymous)" unless factory_class.name
38
+
38
39
  factory_class.name.split("::").last
39
40
  end
40
41
 
@@ -47,6 +48,7 @@ module Openapi3Parser
47
48
  # @return [Boolean]
48
49
  def ==(other)
49
50
  return false unless other.instance_of?(self.class)
51
+
50
52
  message == other.message &&
51
53
  context == other.context &&
52
54
  factory_class == other.factory_class
@@ -6,7 +6,7 @@ module Openapi3Parser
6
6
  # defined for a Components node.
7
7
  # As defined: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#components-object
8
8
  class ComponentKeys
9
- REGEX = /\A[a-zA-Z0-9\.\-_]+\Z/
9
+ REGEX = /\A[a-zA-Z0-9\.\-_]+\Z/.freeze
10
10
 
11
11
  def self.call(input)
12
12
  invalid = input.keys.reject { |key| REGEX.match(key) }
@@ -17,6 +17,7 @@ module Openapi3Parser
17
17
  def duplicate_names_by_in(resolved_input)
18
18
  potential_items = resolved_input.reject do |item|
19
19
  next true unless item.respond_to?(:keys)
20
+
20
21
  item["name"].nil? || item["in"].nil?
21
22
  end
22
23
 
@@ -12,7 +12,7 @@ module Openapi3Parser
12
12
  [a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?
13
13
  (?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*
14
14
  \Z
15
- }x
15
+ }x.freeze
16
16
 
17
17
  def self.call(input)
18
18
  message = %("#{input}" is not a valid email address)
@@ -9,7 +9,7 @@ module Openapi3Parser
9
9
  / # separating slash
10
10
  ([-+.\w]+|\*) # word (with +, - & .) or asterisk
11
11
  \Z
12
- }x
12
+ }x.freeze
13
13
 
14
14
  def self.call(input)
15
15
  message = %("#{input}" is not a valid media type)
@@ -8,8 +8,8 @@ module Openapi3Parser
8
8
  using ArraySentence
9
9
  private_class_method :new
10
10
 
11
- def self.call(*args)
12
- new.call(*args)
11
+ def self.call(*args, **kwargs)
12
+ new.call(*args, **kwargs)
13
13
  end
14
14
 
15
15
  def call(validatable,
@@ -21,6 +21,7 @@ module Openapi3Parser
21
21
 
22
22
  def build_errors
23
23
  return "Expected a string" unless given_reference.is_a?(String)
24
+
24
25
  begin
25
26
  uri = URI.parse(given_reference)
26
27
  rescue URI::Error
@@ -31,6 +32,7 @@ module Openapi3Parser
31
32
 
32
33
  def check_fragment(uri)
33
34
  return if uri.fragment.nil? || uri.fragment.empty?
35
+
34
36
  first_char = uri.fragment[0]
35
37
 
36
38
  "Invalid JSON pointer, expected a root slash" if first_char != "/"
@@ -8,8 +8,8 @@ module Openapi3Parser
8
8
  using ArraySentence
9
9
  private_class_method :new
10
10
 
11
- def self.call(*args)
12
- new.call(*args)
11
+ def self.call(*args, **kwargs)
12
+ new.call(*args, **kwargs)
13
13
  end
14
14
 
15
15
  def call(validatable,
@@ -8,8 +8,8 @@ module Openapi3Parser
8
8
  using ArraySentence
9
9
  private_class_method :new
10
10
 
11
- def self.call(*args)
12
- new.call(*args)
11
+ def self.call(*args, **kwargs)
12
+ new.call(*args, **kwargs)
13
13
  end
14
14
 
15
15
  def call(validatable,
@@ -38,6 +38,7 @@ module Openapi3Parser
38
38
  def unexpected_fields(input, allowed_fields, allow_extensions)
39
39
  extra_keys = input.keys - allowed_fields
40
40
  return extra_keys unless allow_extensions
41
+
41
42
  extra_keys.reject { |key| key =~ NodeFactory::EXTENSION_REGEX }
42
43
  end
43
44
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Openapi3Parser
4
- VERSION = "0.7.0"
4
+ VERSION = "0.8.0"
5
5
  end
@@ -27,11 +27,13 @@ Gem::Specification.new do |spec|
27
27
  spec.required_ruby_version = ">= 2.4.0"
28
28
 
29
29
  spec.add_dependency "commonmarker", "~> 0.17"
30
-
31
- spec.add_development_dependency "bundler", "~> 1.15"
32
- spec.add_development_dependency "byebug", "~> 10.0"
33
- spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "rspec", "~> 3.6"
35
- spec.add_development_dependency "rubocop", "~> 0.53.0"
36
- spec.add_development_dependency "webmock", "~> 3.1"
30
+ spec.add_dependency "psych", "~> 3.1"
31
+
32
+ spec.add_development_dependency "bundler"
33
+ spec.add_development_dependency "byebug", "~> 11.0"
34
+ spec.add_development_dependency "rake", "~> 13.0"
35
+ spec.add_development_dependency "rspec", "~> 3.9"
36
+ spec.add_development_dependency "rubocop", "~> 0.79.0"
37
+ spec.add_development_dependency "simplecov", "~> 0.17"
38
+ spec.add_development_dependency "webmock", "~> 3.8"
37
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi3_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Dew
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-11 00:00:00.000000000 Z
11
+ date: 2020-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commonmarker
@@ -25,89 +25,117 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.17'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: psych
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.15'
34
- type: :development
33
+ version: '3.1'
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.15'
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: byebug
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '10.0'
61
+ version: '11.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '10.0'
68
+ version: '11.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '10.0'
75
+ version: '13.0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '10.0'
82
+ version: '13.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rspec
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '3.6'
89
+ version: '3.9'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '3.6'
96
+ version: '3.9'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 0.53.0
103
+ version: 0.79.0
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 0.53.0
110
+ version: 0.79.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.17'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.17'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: webmock
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - "~>"
102
130
  - !ruby/object:Gem::Version
103
- version: '3.1'
131
+ version: '3.8'
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
136
  - - "~>"
109
137
  - !ruby/object:Gem::Version
110
- version: '3.1'
138
+ version: '3.8'
111
139
  description: |2
112
140
  A tool to parse and validate OpenAPI V3 files.
113
141
  Aims to provide complete compatibility with the OpenAPI specification and