openapi_parser 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yaml +9 -2
- data/CHANGELOG.md +6 -0
- data/Rakefile +1 -1
- data/Steepfile +3 -3
- data/lib/openapi_parser/errors.rb +11 -0
- data/lib/openapi_parser/{schema_validators → schema_validator}/all_of_validator.rb +4 -0
- data/lib/openapi_parser/{schema_validators → schema_validator}/any_of_validator.rb +3 -0
- data/lib/openapi_parser/{schema_validators → schema_validator}/array_validator.rb +9 -0
- data/lib/openapi_parser/{schema_validators → schema_validator}/base.rb +1 -1
- data/lib/openapi_parser/{schema_validators → schema_validator}/one_of_validator.rb +3 -0
- data/lib/openapi_parser/{schema_validators → schema_validator}/unspecified_type_validator.rb +1 -1
- data/lib/openapi_parser/schema_validator.rb +15 -15
- data/lib/openapi_parser/schemas/classes.rb +1 -0
- data/lib/openapi_parser/schemas/info.rb +6 -0
- data/lib/openapi_parser/schemas/openapi.rb +4 -0
- data/lib/openapi_parser/schemas.rb +1 -0
- data/lib/openapi_parser/version.rb +1 -1
- data/lib/openapi_parser.rb +6 -2
- data/openapi_parser.gemspec +1 -1
- data/sig/openapi_parser/config.rbs +2 -0
- data/sig/openapi_parser/errors.rbs +22 -0
- data/sig/openapi_parser/reference_expander.rbs +3 -0
- data/sig/openapi_parser/schema_validators/base.rbs +4 -3
- data/sig/types.rbs +5 -0
- data/sig/wip_types.rbs +0 -3
- metadata +25 -50
- /data/lib/openapi_parser/{schema_validators → schema_validator}/boolean_validator.rb +0 -0
- /data/lib/openapi_parser/{schema_validators → schema_validator}/enumable.rb +0 -0
- /data/lib/openapi_parser/{schema_validators → schema_validator}/float_validator.rb +0 -0
- /data/lib/openapi_parser/{schema_validators → schema_validator}/integer_validator.rb +0 -0
- /data/lib/openapi_parser/{schema_validators → schema_validator}/minimum_maximum.rb +0 -0
- /data/lib/openapi_parser/{schema_validators → schema_validator}/nil_validator.rb +0 -0
- /data/lib/openapi_parser/{schema_validators → schema_validator}/object_validator.rb +0 -0
- /data/lib/openapi_parser/{schema_validators → schema_validator}/options.rb +0 -0
- /data/lib/openapi_parser/{schema_validators → schema_validator}/string_validator.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00f123cd8511ebd3cbe2f48ec901285d591a93ac1a56d2693f2ba896aebdf076
|
4
|
+
data.tar.gz: 263634fb1891c2fae9756c64e3fb0d0b3832484aced219b6091a7af9db3e6793
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f58453f7daa0e73156cd221e1027cd7da7ecb8e63ce13fdee538c544380a763fa6c1b1de52e6a3a191e0f54c4fbde2ba1fd747d88ec5418a25075adcb1f246f
|
7
|
+
data.tar.gz: 9ebff3ee048466e02918cc6993de56147b640903418a1fbff9a6669a277c72954541c441bc2f7acdfff555ee4765c4392e7c3e7367235caff7774db01048f1ea
|
data/.github/workflows/ci.yaml
CHANGED
@@ -5,8 +5,15 @@ jobs:
|
|
5
5
|
strategy:
|
6
6
|
fail-fast: false
|
7
7
|
matrix:
|
8
|
-
os:
|
9
|
-
|
8
|
+
os:
|
9
|
+
- ubuntu-latest
|
10
|
+
- macos-latest
|
11
|
+
ruby:
|
12
|
+
- "2.7"
|
13
|
+
- "3.0"
|
14
|
+
- "3.1"
|
15
|
+
- "3.2"
|
16
|
+
- ruby-head
|
10
17
|
runs-on: ${{ matrix.os }}
|
11
18
|
steps:
|
12
19
|
- uses: actions/checkout@v2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## Unreleased
|
2
2
|
|
3
|
+
## 1.1.0 (2023-10-15)
|
4
|
+
### Added
|
5
|
+
* Support for uniqueItems in array #154
|
6
|
+
* Fix nullable field does not work with allOf, anyOf and oneOf keyword #128
|
7
|
+
* drop ruby 2.6 #158
|
8
|
+
|
3
9
|
## 1.0.0 (2021-02-03)
|
4
10
|
### Added
|
5
11
|
* Add date-time format validation #126
|
data/Rakefile
CHANGED
data/Steepfile
CHANGED
@@ -4,8 +4,8 @@ target :lib do
|
|
4
4
|
|
5
5
|
check "lib/openapi_parser.rb"
|
6
6
|
check "lib/openapi_parser/config.rb"
|
7
|
-
check "lib/openapi_parser/
|
8
|
-
check "lib/openapi_parser/
|
7
|
+
check "lib/openapi_parser/schema_validator/options.rb"
|
8
|
+
check "lib/openapi_parser/schema_validator/base.rb"
|
9
9
|
|
10
|
-
library 'uri'
|
10
|
+
library 'uri', 'json', 'pathname'
|
11
11
|
end
|
@@ -272,4 +272,15 @@ module OpenAPIParser
|
|
272
272
|
"#{@reference} #{@value.inspect} contains fewer than min items"
|
273
273
|
end
|
274
274
|
end
|
275
|
+
|
276
|
+
class NotUniqueItems < OpenAPIError
|
277
|
+
def initialize(value, reference)
|
278
|
+
super(reference)
|
279
|
+
@value = value
|
280
|
+
end
|
281
|
+
|
282
|
+
def message
|
283
|
+
"#{@reference} #{@value.inspect} contains duplicate items"
|
284
|
+
end
|
285
|
+
end
|
275
286
|
end
|
@@ -5,6 +5,10 @@ class OpenAPIParser::SchemaValidator
|
|
5
5
|
# @param [Object] value
|
6
6
|
# @param [OpenAPIParser::Schemas::Schema] schema
|
7
7
|
def coerce_and_validate(value, schema, **keyword_args)
|
8
|
+
if value.nil? && schema.nullable
|
9
|
+
return [value, nil]
|
10
|
+
end
|
11
|
+
|
8
12
|
# if any schema return error, it's not valida all of value
|
9
13
|
remaining_keys = value.kind_of?(Hash) ? value.keys : []
|
10
14
|
nested_additional_properties = false
|
@@ -3,6 +3,9 @@ class OpenAPIParser::SchemaValidator
|
|
3
3
|
# @param [Object] value
|
4
4
|
# @param [OpenAPIParser::Schemas::Schema] schema
|
5
5
|
def coerce_and_validate(value, schema, **_keyword_args)
|
6
|
+
if value.nil? && schema.nullable
|
7
|
+
return [value, nil]
|
8
|
+
end
|
6
9
|
if schema.discriminator
|
7
10
|
return validate_discriminator_schema(schema.discriminator, value)
|
8
11
|
end
|
@@ -8,6 +8,9 @@ class OpenAPIParser::SchemaValidator
|
|
8
8
|
value, err = validate_max_min_items(value, schema)
|
9
9
|
return [nil, err] if err
|
10
10
|
|
11
|
+
value, err = validate_unique_items(value, schema)
|
12
|
+
return [nil, err] if err
|
13
|
+
|
11
14
|
# array type have an schema in items property
|
12
15
|
items_schema = schema.items
|
13
16
|
coerced_values = value.map do |v|
|
@@ -28,5 +31,11 @@ class OpenAPIParser::SchemaValidator
|
|
28
31
|
|
29
32
|
[value, nil]
|
30
33
|
end
|
34
|
+
|
35
|
+
def validate_unique_items(value, schema)
|
36
|
+
return [nil, OpenAPIParser::NotUniqueItems.new(value, schema.object_reference)] if schema.uniqueItems && value.length != value.uniq.length
|
37
|
+
|
38
|
+
[value, nil]
|
39
|
+
end
|
31
40
|
end
|
32
41
|
end
|
@@ -14,7 +14,7 @@ class OpenAPIParser::SchemaValidator
|
|
14
14
|
|
15
15
|
def validate_discriminator_schema(discriminator, value, parent_discriminator_schemas: [])
|
16
16
|
property_name = discriminator.property_name
|
17
|
-
|
17
|
+
if property_name.nil? || !value.key?(property_name)
|
18
18
|
return [nil, OpenAPIParser::NotExistDiscriminatorPropertyName.new(discriminator.property_name, value, discriminator.object_reference)]
|
19
19
|
end
|
20
20
|
mapping_key = value[property_name]
|
@@ -3,6 +3,9 @@ class OpenAPIParser::SchemaValidator
|
|
3
3
|
# @param [Object] value
|
4
4
|
# @param [OpenAPIParser::Schemas::Schema] schema
|
5
5
|
def coerce_and_validate(value, schema, **_keyword_args)
|
6
|
+
if value.nil? && schema.nullable
|
7
|
+
return [value, nil]
|
8
|
+
end
|
6
9
|
if schema.discriminator
|
7
10
|
return validate_discriminator_schema(schema.discriminator, value)
|
8
11
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative '
|
3
|
-
require_relative '
|
4
|
-
require_relative '
|
5
|
-
require_relative '
|
6
|
-
require_relative '
|
7
|
-
require_relative '
|
8
|
-
require_relative '
|
9
|
-
require_relative '
|
10
|
-
require_relative '
|
11
|
-
require_relative '
|
12
|
-
require_relative '
|
13
|
-
require_relative '
|
14
|
-
require_relative '
|
15
|
-
require_relative '
|
1
|
+
require_relative 'schema_validator/options'
|
2
|
+
require_relative 'schema_validator/enumable'
|
3
|
+
require_relative 'schema_validator/minimum_maximum'
|
4
|
+
require_relative 'schema_validator/base'
|
5
|
+
require_relative 'schema_validator/string_validator'
|
6
|
+
require_relative 'schema_validator/integer_validator'
|
7
|
+
require_relative 'schema_validator/float_validator'
|
8
|
+
require_relative 'schema_validator/boolean_validator'
|
9
|
+
require_relative 'schema_validator/object_validator'
|
10
|
+
require_relative 'schema_validator/array_validator'
|
11
|
+
require_relative 'schema_validator/any_of_validator'
|
12
|
+
require_relative 'schema_validator/all_of_validator'
|
13
|
+
require_relative 'schema_validator/one_of_validator'
|
14
|
+
require_relative 'schema_validator/nil_validator'
|
15
|
+
require_relative 'schema_validator/unspecified_type_validator'
|
16
16
|
|
17
17
|
class OpenAPIParser::SchemaValidator
|
18
18
|
# validate value by schema
|
@@ -29,6 +29,10 @@ module OpenAPIParser::Schemas
|
|
29
29
|
# @return [Components, nil]
|
30
30
|
openapi_attr_object :components, Components, reference: false
|
31
31
|
|
32
|
+
# @!attribute [r] info
|
33
|
+
# @return [Info, nil]
|
34
|
+
openapi_attr_object :info, Info, reference: false
|
35
|
+
|
32
36
|
# @return [OpenAPIParser::RequestOperation, nil]
|
33
37
|
def request_operation(http_method, request_path)
|
34
38
|
OpenAPIParser::RequestOperation.create(http_method, request_path, @path_item_finder, @config)
|
data/lib/openapi_parser.rb
CHANGED
@@ -43,13 +43,16 @@ module OpenAPIParser
|
|
43
43
|
def load_uri(uri, config:, schema_registry:)
|
44
44
|
# Open-uri doesn't open file scheme uri, so we try to open file path directly
|
45
45
|
# File scheme uri which points to a remote file is not supported.
|
46
|
+
uri_path = uri.path
|
47
|
+
raise "file not found" if uri_path.nil?
|
48
|
+
|
46
49
|
content = if uri.scheme == 'file'
|
47
|
-
open(
|
50
|
+
open(uri_path)&.read
|
48
51
|
elsif uri.is_a?(OpenURI::OpenRead)
|
49
52
|
uri.open()&.read
|
50
53
|
end
|
51
54
|
|
52
|
-
extension = Pathname.new(
|
55
|
+
extension = Pathname.new(uri_path).extname
|
53
56
|
load_hash(parse_file(content, extension), config: config, uri: uri, schema_registry: schema_registry)
|
54
57
|
end
|
55
58
|
|
@@ -85,6 +88,7 @@ module OpenAPIParser
|
|
85
88
|
end
|
86
89
|
|
87
90
|
def parse_json(content)
|
91
|
+
raise "json content is nil" unless content
|
88
92
|
JSON.parse(content)
|
89
93
|
end
|
90
94
|
|
data/openapi_parser.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = 'parser for OpenAPI 3.0 or later'
|
13
13
|
spec.homepage = 'https://github.com/ota42y/openapi_parser'
|
14
14
|
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = ">= 2.
|
15
|
+
spec.required_ruby_version = ">= 2.7.0"
|
16
16
|
|
17
17
|
# Specify which files should be added to the gem when it is released.
|
18
18
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -2,6 +2,8 @@
|
|
2
2
|
module OpenAPIParser
|
3
3
|
class Config
|
4
4
|
@config: untyped
|
5
|
+
@request_validator_options: OpenAPIParser::SchemaValidator::Options
|
6
|
+
@response_validate_options: OpenAPIParser::SchemaValidator::ResponseValidateOptions
|
5
7
|
alias request_body_options request_validator_options
|
6
8
|
alias path_params_options request_validator_options
|
7
9
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module OpenAPIParser
|
2
|
+
class OpenAPIError < StandardError
|
3
|
+
def initialize: (untyped reference) -> untyped
|
4
|
+
end
|
5
|
+
|
6
|
+
class ValidateError < OpenAPIError
|
7
|
+
def initialize: (untyped data, (String | nil) type, untyped reference) -> untyped
|
8
|
+
def message: -> String
|
9
|
+
|
10
|
+
def self.build_error_result: (Object value, OpenAPIParser::Schemas::Schema schema) -> [nil, OpenAPIParser::ValidateError]
|
11
|
+
end
|
12
|
+
|
13
|
+
class NotExistDiscriminatorMappedSchema < OpenAPIError
|
14
|
+
def initialize: (untyped mapped_schema_reference, untyped reference) -> untyped
|
15
|
+
def message: -> String
|
16
|
+
end
|
17
|
+
|
18
|
+
class NotExistDiscriminatorPropertyName < OpenAPIError
|
19
|
+
def initialize: (untyped mapped_schema_reference, untyped value, untyped reference) -> untyped
|
20
|
+
def message: -> String
|
21
|
+
end
|
22
|
+
end
|
@@ -4,14 +4,15 @@ module OpenAPIParser
|
|
4
4
|
class Base
|
5
5
|
@coerce_value: bool | nil
|
6
6
|
|
7
|
-
def initialize: (OpenAPIParser::SchemaValidator::Validatable validatable, (bool | nil) coerce_value) -> untyped
|
8
7
|
attr_reader validatable: OpenAPIParser::SchemaValidator::Validatable
|
9
|
-
|
8
|
+
|
9
|
+
def initialize: (OpenAPIParser::SchemaValidator::Validatable validatable, (bool | nil) coerce_value) -> untyped
|
10
|
+
def coerce_and_validate: (Object _value, OpenAPIParser::Schemas::Schema _schema, **untyped) -> [untyped, (ValidateError | NotExistDiscriminatorMappedSchema | nil)]
|
10
11
|
def validate_discriminator_schema: (
|
11
12
|
OpenAPIParser::Schemas::Discriminator discriminator,
|
12
13
|
Hash[String, bot] value,
|
13
14
|
?parent_discriminator_schemas: Array[OpenAPIParser::Schemas::Schema]
|
14
|
-
) -> [Object | nil, OpenAPIParser::
|
15
|
+
) -> [Object | nil, OpenAPIParser::OpenAPIError]
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
data/sig/types.rbs
CHANGED
data/sig/wip_types.rbs
CHANGED
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:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ota42y
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,34 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: pry
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.12.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.12.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: pry-byebug
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
42
|
name: rake
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,27 +172,28 @@ files:
|
|
200
172
|
- lib/openapi_parser/reference_expander.rb
|
201
173
|
- lib/openapi_parser/request_operation.rb
|
202
174
|
- lib/openapi_parser/schema_validator.rb
|
203
|
-
- lib/openapi_parser/
|
204
|
-
- lib/openapi_parser/
|
205
|
-
- lib/openapi_parser/
|
206
|
-
- lib/openapi_parser/
|
207
|
-
- lib/openapi_parser/
|
208
|
-
- lib/openapi_parser/
|
209
|
-
- lib/openapi_parser/
|
210
|
-
- lib/openapi_parser/
|
211
|
-
- lib/openapi_parser/
|
212
|
-
- lib/openapi_parser/
|
213
|
-
- lib/openapi_parser/
|
214
|
-
- lib/openapi_parser/
|
215
|
-
- lib/openapi_parser/
|
216
|
-
- lib/openapi_parser/
|
217
|
-
- lib/openapi_parser/
|
175
|
+
- lib/openapi_parser/schema_validator/all_of_validator.rb
|
176
|
+
- lib/openapi_parser/schema_validator/any_of_validator.rb
|
177
|
+
- lib/openapi_parser/schema_validator/array_validator.rb
|
178
|
+
- lib/openapi_parser/schema_validator/base.rb
|
179
|
+
- lib/openapi_parser/schema_validator/boolean_validator.rb
|
180
|
+
- lib/openapi_parser/schema_validator/enumable.rb
|
181
|
+
- lib/openapi_parser/schema_validator/float_validator.rb
|
182
|
+
- lib/openapi_parser/schema_validator/integer_validator.rb
|
183
|
+
- lib/openapi_parser/schema_validator/minimum_maximum.rb
|
184
|
+
- lib/openapi_parser/schema_validator/nil_validator.rb
|
185
|
+
- lib/openapi_parser/schema_validator/object_validator.rb
|
186
|
+
- lib/openapi_parser/schema_validator/one_of_validator.rb
|
187
|
+
- lib/openapi_parser/schema_validator/options.rb
|
188
|
+
- lib/openapi_parser/schema_validator/string_validator.rb
|
189
|
+
- lib/openapi_parser/schema_validator/unspecified_type_validator.rb
|
218
190
|
- lib/openapi_parser/schemas.rb
|
219
191
|
- lib/openapi_parser/schemas/base.rb
|
220
192
|
- lib/openapi_parser/schemas/classes.rb
|
221
193
|
- lib/openapi_parser/schemas/components.rb
|
222
194
|
- lib/openapi_parser/schemas/discriminator.rb
|
223
195
|
- lib/openapi_parser/schemas/header.rb
|
196
|
+
- lib/openapi_parser/schemas/info.rb
|
224
197
|
- lib/openapi_parser/schemas/media_type.rb
|
225
198
|
- lib/openapi_parser/schemas/openapi.rb
|
226
199
|
- lib/openapi_parser/schemas/operation.rb
|
@@ -236,6 +209,8 @@ files:
|
|
236
209
|
- openapi_parser.gemspec
|
237
210
|
- sig/openapi_parser.rbs
|
238
211
|
- sig/openapi_parser/config.rbs
|
212
|
+
- sig/openapi_parser/errors.rbs
|
213
|
+
- sig/openapi_parser/reference_expander.rbs
|
239
214
|
- sig/openapi_parser/schema_validator.rbs
|
240
215
|
- sig/openapi_parser/schema_validators/base.rbs
|
241
216
|
- sig/openapi_parser/schema_validators/options.rbs
|
@@ -247,7 +222,7 @@ homepage: https://github.com/ota42y/openapi_parser
|
|
247
222
|
licenses:
|
248
223
|
- MIT
|
249
224
|
metadata: {}
|
250
|
-
post_install_message:
|
225
|
+
post_install_message:
|
251
226
|
rdoc_options: []
|
252
227
|
require_paths:
|
253
228
|
- lib
|
@@ -255,15 +230,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
255
230
|
requirements:
|
256
231
|
- - ">="
|
257
232
|
- !ruby/object:Gem::Version
|
258
|
-
version: 2.
|
233
|
+
version: 2.7.0
|
259
234
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
260
235
|
requirements:
|
261
236
|
- - ">="
|
262
237
|
- !ruby/object:Gem::Version
|
263
238
|
version: '0'
|
264
239
|
requirements: []
|
265
|
-
rubygems_version: 3.
|
266
|
-
signing_key:
|
240
|
+
rubygems_version: 3.4.20
|
241
|
+
signing_key:
|
267
242
|
specification_version: 4
|
268
243
|
summary: OpenAPI3 parser
|
269
244
|
test_files: []
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|