openapi_parser 1.0.0.beta1 → 1.0.0

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: e383e6ff9f0d2a6ac67fda1ac8663b82c249449a7c1cff616a72fb608344a816
4
- data.tar.gz: 53c6a442a5f170f5190197aa17a805a707fd586d7b4d0fc4c259ed8af46dc2bd
3
+ metadata.gz: 3019c8458c35d159f7c8eccc8f8203d39826438804460cccd1383f9e29b95299
4
+ data.tar.gz: 3471fed71a9d1f81688d87a0c907a0ab4c0529ca3e4a9d40159403b88238d1a6
5
5
  SHA512:
6
- metadata.gz: 3cd78f54ac0bb0bca68e9538f3f33968b7815b76d88c39908735da2f18936118ecc66ec57a97ac491f2b0fdc7fd4985e312b8b32a4051d22a2242ed8ea55608f
7
- data.tar.gz: 22fcb549a4c134350274be73bc59114309d612f096b70dfd5633fe049b9b2111c176809575b2ce89fc30a2db3a8cda633c5ce18b82a58a418cd95d76ce23791a
6
+ metadata.gz: d9f7ba65682079456e26ff03d4be816ad6f61b9bb9224c4cf37157a0bb4d4455d17c3e36fbadd0f557700d9926f69a50ae8ebdc9041412304b12b05feb91df4e
7
+ data.tar.gz: fd611630b787af1e69a003de92c01f8c83d9e9d6e8be68fe66fdba6a93ce2a8ca412c89a00fa35bcf4d7441fe10c309ec9eb9f3e91659957429b0375629a3671
@@ -6,7 +6,7 @@ jobs:
6
6
  fail-fast: false
7
7
  matrix:
8
8
  os: [ubuntu-latest, macos-latest]
9
- ruby: [2.6, 2.7, '3.0', head]
9
+ ruby: [2.6, 2.7, '3.0', '3.1']
10
10
  runs-on: ${{ matrix.os }}
11
11
  steps:
12
12
  - uses: actions/checkout@v2
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.0.3
1
+ 3.1.0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 1.0.0 (2021-02-03)
4
+ ### Added
5
+ * Add date-time format validation #126
6
+
3
7
  ## 1.0.0.beta1 (2021-12-15)
4
8
  ### Added
5
9
  * Add strict_reference_validation config and implementation to address/implement #29 #123
@@ -206,6 +206,17 @@ module OpenAPIParser
206
206
  end
207
207
  end
208
208
 
209
+ class InvalidDateTimeFormat < OpenAPIError
210
+ def initialize(value, reference)
211
+ super(reference)
212
+ @value = value
213
+ end
214
+
215
+ def message
216
+ "#{@reference} Value: #{@value.inspect} is not conformant with date-time format"
217
+ end
218
+ end
219
+
209
220
  class NotExistStatusCodeDefinition < OpenAPIError
210
221
  def message
211
222
  "#{@reference} status code definition does not exist"
@@ -16,11 +16,6 @@ class OpenAPIParser::SchemaValidator
16
16
  value, err = pattern_validate(value, schema)
17
17
  return [nil, err] if err
18
18
 
19
- unless @datetime_coerce_class.nil?
20
- value, err = coerce_date_time(value, schema)
21
- return [nil, err] if err
22
- end
23
-
24
19
  value, err = validate_max_min_length(value, schema)
25
20
  return [nil, err] if err
26
21
 
@@ -33,28 +28,14 @@ class OpenAPIParser::SchemaValidator
33
28
  value, err = validate_date_format(value, schema)
34
29
  return [nil, err] if err
35
30
 
31
+ value, err = validate_datetime_format(value, schema)
32
+ return [nil, err] if err
33
+
36
34
  [value, nil]
37
35
  end
38
36
 
39
37
  private
40
38
 
41
- # @param [OpenAPIParser::Schemas::Schema] schema
42
- def coerce_date_time(value, schema)
43
- return parse_date_time(value, schema) if schema.format == 'date-time'
44
-
45
- [value, nil]
46
- end
47
-
48
- def parse_date_time(value, schema)
49
- begin
50
- return @datetime_coerce_class.parse(value), nil
51
- rescue ArgumentError => e
52
- raise e unless e.message =~ /invalid date/
53
- end
54
-
55
- OpenAPIParser::ValidateError.build_error_result(value, schema)
56
- end
57
-
58
39
  # @param [OpenAPIParser::Schemas::Schema] schema
59
40
  def pattern_validate(value, schema)
60
41
  # pattern support string only so put this
@@ -101,5 +82,27 @@ class OpenAPIParser::SchemaValidator
101
82
 
102
83
  return [value, nil]
103
84
  end
85
+
86
+ def validate_datetime_format(value, schema)
87
+ return [value, nil] unless schema.format == 'date-time'
88
+
89
+ begin
90
+ if @datetime_coerce_class.nil?
91
+ # validate only
92
+ DateTime.rfc3339(value)
93
+ [value, nil]
94
+ else
95
+ # validate and coerce
96
+ if @datetime_coerce_class == Time
97
+ [DateTime.rfc3339(value).to_time, nil]
98
+ else
99
+ [@datetime_coerce_class.rfc3339(value), nil]
100
+ end
101
+ end
102
+ rescue ArgumentError
103
+ # when rfc3339(value) failed
104
+ [nil, OpenAPIParser::InvalidDateTimeFormat.new(value, schema.object_reference)]
105
+ end
106
+ end
104
107
  end
105
108
  end
@@ -1,3 +1,3 @@
1
1
  module OpenAPIParser
2
- VERSION = '1.0.0.beta1'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -25,11 +25,17 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency 'bundler', '>= 1.16'
27
27
  spec.add_development_dependency 'fincop'
28
- spec.add_development_dependency 'pry', '~> 0.12.0'
29
- spec.add_development_dependency 'pry-byebug'
28
+
29
+ if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("3.2.0")
30
+ spec.add_development_dependency 'pry', '~> 0.12.0'
31
+ spec.add_development_dependency 'pry-byebug'
32
+ end
30
33
  spec.add_development_dependency 'rake', '>= 12.3.3'
31
34
  spec.add_development_dependency 'rspec', '~> 3.0'
32
35
  spec.add_development_dependency 'rspec-parameterized'
33
36
  spec.add_development_dependency 'simplecov'
34
37
  spec.add_development_dependency "steep"
38
+ # for steep
39
+ # https://github.com/soutaro/steep/issues/466
40
+ spec.add_development_dependency "activesupport", '~> 6.0'
35
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ota42y
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-15 00:00:00.000000000 Z
11
+ date: 2022-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: activesupport
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '6.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '6.0'
139
153
  description: parser for OpenAPI 3.0 or later
140
154
  email:
141
155
  - ota42y@gmail.com
@@ -244,11 +258,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
244
258
  version: 2.6.0
245
259
  required_rubygems_version: !ruby/object:Gem::Requirement
246
260
  requirements:
247
- - - ">"
261
+ - - ">="
248
262
  - !ruby/object:Gem::Version
249
- version: 1.3.1
263
+ version: '0'
250
264
  requirements: []
251
- rubygems_version: 3.2.32
265
+ rubygems_version: 3.3.3
252
266
  signing_key:
253
267
  specification_version: 4
254
268
  summary: OpenAPI3 parser