openapi_parser 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/openapi_parser/concerns/media_type_selectable.rb +21 -19
- data/lib/openapi_parser/concerns/parser/hash_body.rb +1 -1
- data/lib/openapi_parser/schemas/request_body.rb +8 -1
- data/lib/openapi_parser/schemas/response.rb +8 -1
- data/lib/openapi_parser/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01ffcf763ea2797df03cd91cd162d4031c504d5f7ece8327e4e0cbad989972c4
|
4
|
+
data.tar.gz: 518c4c86cababa47d3a6f0520fbeeec28d953d40ea9e7e3e4ab26150eaf917b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a59505448fa9fdbe16e6117c86eb885d3343ece1f6e3ed18dffaa44727f6d99e71f81dc48661d311c8e1524d09c21f9c78e8a9a13d921b7478c3bdae0110891b
|
7
|
+
data.tar.gz: ecdfd1fc6b2b159e8991b9d187decc834958f2970bcbef710739b36b09a44409dce0ac425129459f7d5f86236b7f72227bd06d108790ee6e2cfcff5a7a434736
|
data/CHANGELOG.md
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
module OpenAPIParser::MediaTypeSelectable
|
2
|
-
|
3
|
-
# @param [String] content_type
|
4
|
-
# @param [Hash{String => OpenAPIParser::Schemas::MediaType}] content
|
5
|
-
# @return [OpenAPIParser::Schemas::MediaType, nil]
|
6
|
-
def select_media_type(content_type, content)
|
7
|
-
return nil unless content_type
|
2
|
+
private
|
8
3
|
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
# select media type by content_type (consider wild card definition)
|
5
|
+
# @param [String] content_type
|
6
|
+
# @param [Hash{String => OpenAPIParser::Schemas::MediaType}] content
|
7
|
+
# @return [OpenAPIParser::Schemas::MediaType, nil]
|
8
|
+
def select_media_type_from_content(content_type, content)
|
9
|
+
return nil unless content_type
|
12
10
|
|
13
|
-
|
14
|
-
|
11
|
+
if (media_type = content[content_type])
|
12
|
+
return media_type
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
end
|
15
|
+
# application/json => [application, json]
|
16
|
+
splited = content_type.split('/')
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
if (media_type = content["#{splited.first}/*"])
|
19
|
+
return media_type
|
20
|
+
end
|
23
21
|
|
24
|
-
|
25
|
-
|
22
|
+
if (media_type = content['*/*'])
|
23
|
+
return media_type
|
24
|
+
end
|
25
|
+
|
26
|
+
nil
|
27
|
+
end
|
26
28
|
end
|
@@ -4,7 +4,7 @@ module OpenAPIParser::Parser::HashBody
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def openapi_attr_hash_body_objects(name, klass, options = {})
|
7
|
-
#options[:reject_keys] = options[:reject_keys] ? options[:reject_keys].map(&:to_s) : []
|
7
|
+
# options[:reject_keys] = options[:reject_keys] ? options[:reject_keys].map(&:to_s) : []
|
8
8
|
|
9
9
|
target_klass.send(:attr_reader, name)
|
10
10
|
_openapi_attr_hash_body_objects[name] = ::OpenAPIParser::SchemaLoader::HashBodyLoader.new(name, options.merge(klass: klass))
|
@@ -18,10 +18,17 @@ module OpenAPIParser::Schemas
|
|
18
18
|
# @param [Hash] params
|
19
19
|
# @param [OpenAPIParser::SchemaValidator::Options] options
|
20
20
|
def validate_request_body(content_type, params, options)
|
21
|
-
media_type = select_media_type(content_type
|
21
|
+
media_type = select_media_type(content_type)
|
22
22
|
return params unless media_type
|
23
23
|
|
24
24
|
media_type.validate_parameter(params, options)
|
25
25
|
end
|
26
|
+
|
27
|
+
# select media type by content_type (consider wild card definition)
|
28
|
+
# @param [String] content_type
|
29
|
+
# @return [OpenAPIParser::Schemas::MediaType, nil]
|
30
|
+
def select_media_type(content_type)
|
31
|
+
select_media_type_from_content(content_type, content)
|
32
|
+
end
|
26
33
|
end
|
27
34
|
end
|
@@ -12,11 +12,18 @@ module OpenAPIParser::Schemas
|
|
12
12
|
openapi_attr_hash_object :content, MediaType, reference: false
|
13
13
|
|
14
14
|
def validate_parameter(content_type, params)
|
15
|
-
media_type = select_media_type(content_type
|
15
|
+
media_type = select_media_type(content_type)
|
16
16
|
return nil unless media_type
|
17
17
|
|
18
18
|
options = ::OpenAPIParser::SchemaValidator::Options.new # response validator not support any options
|
19
19
|
media_type.validate_parameter(params, options)
|
20
20
|
end
|
21
|
+
|
22
|
+
# select media type by content_type (consider wild card definition)
|
23
|
+
# @param [String] content_type
|
24
|
+
# @return [OpenAPIParser::Schemas::MediaType, nil]
|
25
|
+
def select_media_type(content_type)
|
26
|
+
select_media_type_from_content(content_type, content)
|
27
|
+
end
|
21
28
|
end
|
22
29
|
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.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ota42y
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|