openapi_parser 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yaml +17 -0
- data/CHANGELOG.md +10 -0
- data/README.md +1 -3
- data/lib/openapi_parser/errors.rb +11 -0
- data/lib/openapi_parser/schema_validator.rb +6 -1
- data/lib/openapi_parser/schema_validators/all_of_validator.rb +7 -2
- data/lib/openapi_parser/schema_validators/base.rb +6 -2
- data/lib/openapi_parser/schema_validators/float_validator.rb +3 -3
- data/lib/openapi_parser/schema_validators/integer_validator.rb +3 -5
- data/lib/openapi_parser/schema_validators/object_validator.rb +11 -1
- data/lib/openapi_parser/schema_validators/string_validator.rb +15 -0
- data/lib/openapi_parser/schema_validators/unspecified_type_validator.rb +8 -0
- data/lib/openapi_parser/version.rb +1 -1
- metadata +4 -3
- data/.travis.yml +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1b06e3e4d6ad28828a02c2a4a79140439b9119ac53b73494318386195cc6275
|
4
|
+
data.tar.gz: 4360946a10aa364d8c0de18d773eee3df2ee683373de2178307f52530806e81a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be2a98609d41e4207edff4aaa61687b34dc568cb36e38b37eef42c7edffc836ffb9110465dda772c41025bc0fce125115da370e36949414ceb8902051c81b7b8
|
7
|
+
data.tar.gz: 3047ab4d4ef9f465e9c9373567c11e323ecd135d994002d8578426bdc38d5cdbe5922050d66bdf701551fb10fcb3206029276b49a33e2bc1d755278cb105a9e3
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: ci
|
2
|
+
on: [push]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
strategy:
|
6
|
+
fail-fast: false
|
7
|
+
matrix:
|
8
|
+
os: [ubuntu-latest, macos-latest]
|
9
|
+
ruby: [2.4, 2.5, 2.6, 2.7, '3.0', head]
|
10
|
+
runs-on: ${{ matrix.os }}
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
- uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: ${{ matrix.ruby }}
|
16
|
+
bundler-cache: true
|
17
|
+
- run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
## Unreleased
|
2
2
|
|
3
|
+
## 0.14.0 (2021-05-24)
|
4
|
+
|
5
|
+
### Added
|
6
|
+
* Add basic polymorphism handling #103
|
7
|
+
* Support empty schema as any type #109
|
8
|
+
* Add date format validation for string #102
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
* Fix anyOf coercion to float and integer when value is a non-string type #110
|
12
|
+
|
3
13
|
## 0.13.0 (2021-05-01)
|
4
14
|
* Fix a problem with remote reference to path items which have path parameters #95
|
5
15
|
* Support enum for booleans. #104
|
data/README.md
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# OpenAPI Parser
|
2
|
-
[](https://github.com/ota42y/openapi_parser/actions/workflows/ci.yaml)
|
3
3
|
[](https://badge.fury.io/rb/openapi_parser)
|
4
4
|
[](https://www.rubydoc.info/gems/openapi_parser)
|
5
|
-
[](https://codeclimate.com/github/ota42y/openapi_parser/maintainability)
|
6
|
-
[](https://codeclimate.com/github/ota42y/openapi_parser/test_coverage)
|
7
5
|
[](https://inch-ci.org/github/ota42y/openapi_parser)
|
8
6
|
|
9
7
|
This is OpenAPI3 parser and validator.
|
@@ -189,6 +189,17 @@ module OpenAPIParser
|
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
192
|
+
class InvalidDateFormat < OpenAPIError
|
193
|
+
def initialize(value, reference)
|
194
|
+
super(reference)
|
195
|
+
@value = value
|
196
|
+
end
|
197
|
+
|
198
|
+
def message
|
199
|
+
"#{@reference} Value: #{@value.inspect} is not conformant with date format"
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
192
203
|
class NotExistStatusCodeDefinition < OpenAPIError
|
193
204
|
def message
|
194
205
|
"#{@reference} status code definition does not exist"
|
@@ -12,6 +12,7 @@ require_relative 'schema_validators/any_of_validator'
|
|
12
12
|
require_relative 'schema_validators/all_of_validator'
|
13
13
|
require_relative 'schema_validators/one_of_validator'
|
14
14
|
require_relative 'schema_validators/nil_validator'
|
15
|
+
require_relative 'schema_validators/unspecified_type_validator'
|
15
16
|
|
16
17
|
class OpenAPIParser::SchemaValidator
|
17
18
|
# validate value by schema
|
@@ -113,7 +114,7 @@ class OpenAPIParser::SchemaValidator
|
|
113
114
|
when 'array'
|
114
115
|
array_validator
|
115
116
|
else
|
116
|
-
|
117
|
+
unspecified_type_validator
|
117
118
|
end
|
118
119
|
end
|
119
120
|
|
@@ -156,4 +157,8 @@ class OpenAPIParser::SchemaValidator
|
|
156
157
|
def nil_validator
|
157
158
|
@nil_validator ||= OpenAPIParser::SchemaValidator::NilValidator.new(self, @coerce_value)
|
158
159
|
end
|
160
|
+
|
161
|
+
def unspecified_type_validator
|
162
|
+
@unspecified_type_validator ||= OpenAPIParser::SchemaValidator::UnspecifiedTypeValidator.new(self, @coerce_value)
|
163
|
+
end
|
159
164
|
end
|
@@ -4,13 +4,18 @@ class OpenAPIParser::SchemaValidator
|
|
4
4
|
# coerce and validate value
|
5
5
|
# @param [Object] value
|
6
6
|
# @param [OpenAPIParser::Schemas::Schema] schema
|
7
|
-
def coerce_and_validate(value, schema, **
|
7
|
+
def coerce_and_validate(value, schema, **keyword_args)
|
8
8
|
# if any schema return error, it's not valida all of value
|
9
9
|
remaining_keys = value.kind_of?(Hash) ? value.keys : []
|
10
10
|
nested_additional_properties = false
|
11
11
|
schema.all_of.each do |s|
|
12
12
|
# We need to store the reference to all of, so we can perform strict check on allowed properties
|
13
|
-
_coerced, err = validatable.validate_schema(
|
13
|
+
_coerced, err = validatable.validate_schema(
|
14
|
+
value,
|
15
|
+
s,
|
16
|
+
:parent_all_of => true,
|
17
|
+
parent_discriminator_schemas: keyword_args[:parent_discriminator_schemas]
|
18
|
+
)
|
14
19
|
|
15
20
|
if s.type == "object"
|
16
21
|
remaining_keys -= (s.properties || {}).keys
|
@@ -18,7 +18,7 @@ class OpenAPIParser::SchemaValidator
|
|
18
18
|
raise 'need implement'
|
19
19
|
end
|
20
20
|
|
21
|
-
def validate_discriminator_schema(discriminator, value)
|
21
|
+
def validate_discriminator_schema(discriminator, value, parent_discriminator_schemas: [])
|
22
22
|
unless value.key?(discriminator.property_name)
|
23
23
|
return [nil, OpenAPIParser::NotExistDiscriminatorPropertyName.new(discriminator.property_name, value, discriminator.object_reference)]
|
24
24
|
end
|
@@ -34,7 +34,11 @@ class OpenAPIParser::SchemaValidator
|
|
34
34
|
unless resolved_schema
|
35
35
|
return [nil, OpenAPIParser::NotExistDiscriminatorMappedSchema.new(mapping_target, discriminator.object_reference)]
|
36
36
|
end
|
37
|
-
validatable.validate_schema(
|
37
|
+
validatable.validate_schema(
|
38
|
+
value,
|
39
|
+
resolved_schema,
|
40
|
+
**{discriminator_property_name: discriminator.property_name, parent_discriminator_schemas: parent_discriminator_schemas}
|
41
|
+
)
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
@@ -21,14 +21,14 @@ class OpenAPIParser::SchemaValidator
|
|
21
21
|
|
22
22
|
value, err = check_enum_include(value, schema)
|
23
23
|
return [nil, err] if err
|
24
|
-
|
24
|
+
|
25
25
|
check_minimum_maximum(value, schema)
|
26
26
|
end
|
27
27
|
|
28
28
|
def coerce(value)
|
29
29
|
Float(value)
|
30
|
-
rescue ArgumentError
|
31
|
-
|
30
|
+
rescue ArgumentError, TypeError
|
31
|
+
value
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -23,12 +23,10 @@ class OpenAPIParser::SchemaValidator
|
|
23
23
|
return value if value.kind_of?(Integer)
|
24
24
|
|
25
25
|
begin
|
26
|
-
|
27
|
-
rescue ArgumentError
|
28
|
-
|
26
|
+
Integer(value)
|
27
|
+
rescue ArgumentError, TypeError
|
28
|
+
value
|
29
29
|
end
|
30
|
-
|
31
|
-
value
|
32
30
|
end
|
33
31
|
end
|
34
32
|
end
|
@@ -4,7 +4,7 @@ class OpenAPIParser::SchemaValidator
|
|
4
4
|
# @param [OpenAPIParser::Schemas::Schema] schema
|
5
5
|
# @param [Boolean] parent_all_of true if component is nested under allOf
|
6
6
|
# @param [String, nil] discriminator_property_name discriminator.property_name to ignore checking additional_properties
|
7
|
-
def coerce_and_validate(value, schema, parent_all_of: false, discriminator_property_name: nil)
|
7
|
+
def coerce_and_validate(value, schema, parent_all_of: false, parent_discriminator_schemas: [], discriminator_property_name: nil)
|
8
8
|
return OpenAPIParser::ValidateError.build_error_result(value, schema) unless value.kind_of?(Hash)
|
9
9
|
|
10
10
|
properties = schema.properties || {}
|
@@ -12,6 +12,16 @@ class OpenAPIParser::SchemaValidator
|
|
12
12
|
required_set = schema.required ? schema.required.to_set : Set.new
|
13
13
|
remaining_keys = value.keys
|
14
14
|
|
15
|
+
if schema.discriminator && !parent_discriminator_schemas.include?(schema)
|
16
|
+
return validate_discriminator_schema(
|
17
|
+
schema.discriminator,
|
18
|
+
value,
|
19
|
+
parent_discriminator_schemas: parent_discriminator_schemas + [schema]
|
20
|
+
)
|
21
|
+
else
|
22
|
+
remaining_keys.delete('discriminator')
|
23
|
+
end
|
24
|
+
|
15
25
|
coerced_values = value.map do |name, v|
|
16
26
|
s = properties[name]
|
17
27
|
coerced, err = if s
|
@@ -30,6 +30,9 @@ class OpenAPIParser::SchemaValidator
|
|
30
30
|
value, err = validate_uuid_format(value, schema)
|
31
31
|
return [nil, err] if err
|
32
32
|
|
33
|
+
value, err = validate_date_format(value, schema)
|
34
|
+
return [nil, err] if err
|
35
|
+
|
33
36
|
[value, nil]
|
34
37
|
end
|
35
38
|
|
@@ -86,5 +89,17 @@ class OpenAPIParser::SchemaValidator
|
|
86
89
|
|
87
90
|
return [nil, OpenAPIParser::InvalidUUIDFormat.new(value, schema.object_reference)]
|
88
91
|
end
|
92
|
+
|
93
|
+
def validate_date_format(value, schema)
|
94
|
+
return [value, nil] unless schema.format == 'date'
|
95
|
+
|
96
|
+
begin
|
97
|
+
Date.strptime(value, "%Y-%m-%d")
|
98
|
+
rescue ArgumentError
|
99
|
+
return [nil, OpenAPIParser::InvalidDateFormat.new(value, schema.object_reference)]
|
100
|
+
end
|
101
|
+
|
102
|
+
return [value, nil]
|
103
|
+
end
|
89
104
|
end
|
90
105
|
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: 0.
|
4
|
+
version: 0.14.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-
|
11
|
+
date: 2021-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,11 +129,11 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ".github/workflows/ci.yaml"
|
132
133
|
- ".gitignore"
|
133
134
|
- ".rspec"
|
134
135
|
- ".rubocop.yml"
|
135
136
|
- ".rubocop_ignore.yml"
|
136
|
-
- ".travis.yml"
|
137
137
|
- CHANGELOG.md
|
138
138
|
- CODE_OF_CONDUCT.md
|
139
139
|
- Gemfile
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- lib/openapi_parser/schema_validators/one_of_validator.rb
|
185
185
|
- lib/openapi_parser/schema_validators/options.rb
|
186
186
|
- lib/openapi_parser/schema_validators/string_validator.rb
|
187
|
+
- lib/openapi_parser/schema_validators/unspecified_type_validator.rb
|
187
188
|
- lib/openapi_parser/schemas.rb
|
188
189
|
- lib/openapi_parser/schemas/base.rb
|
189
190
|
- lib/openapi_parser/schemas/classes.rb
|
data/.travis.yml
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
env:
|
2
|
-
global:
|
3
|
-
- CC_TEST_REPORTER_ID=b49a1717b8ff0aef9eced41d0f87d350a88b46d55083ba2e3df8b6f441ae3fb7
|
4
|
-
|
5
|
-
language: ruby
|
6
|
-
|
7
|
-
rvm:
|
8
|
-
- 2.3.8
|
9
|
-
- 2.4.10
|
10
|
-
- 2.5.9
|
11
|
-
- 2.6.7
|
12
|
-
- 2.7.3
|
13
|
-
- 3.0.1
|
14
|
-
- ruby-head
|
15
|
-
|
16
|
-
cache: bundler
|
17
|
-
|
18
|
-
before_script:
|
19
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
20
|
-
- chmod +x ./cc-test-reporter
|
21
|
-
- ./cc-test-reporter before-build
|
22
|
-
|
23
|
-
script: bundle exec rspec
|
24
|
-
|
25
|
-
after_script:
|
26
|
-
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
27
|
-
|
28
|
-
notifications:
|
29
|
-
email: false
|
30
|
-
|
31
|
-
sudo: false
|
32
|
-
|
33
|
-
git:
|
34
|
-
depth: 10
|
35
|
-
|
36
|
-
matrix:
|
37
|
-
allow_failures:
|
38
|
-
- rvm: ruby-head
|