openapi_parser 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fc5651f9e70c443d358fce4dc0e03bb6ecddf38f4862add79ed36f7a0b2a516
4
- data.tar.gz: 153339ab41b7a1d3b9bbf3299b53dce0ce57b4c3cf544bb5cf6dee64e98429f7
3
+ metadata.gz: 01ffcf763ea2797df03cd91cd162d4031c504d5f7ece8327e4e0cbad989972c4
4
+ data.tar.gz: 518c4c86cababa47d3a6f0520fbeeec28d953d40ea9e7e3e4ab26150eaf917b5
5
5
  SHA512:
6
- metadata.gz: 6d116f2b5e22b12cfce469d423e21a711703efaabd04789867fa8dfc312c7818a253bf6a66d6eb437119534d61e02f27dad723f6ce003356a5567f97aded6969
7
- data.tar.gz: c69e9b18b3bc0933287602050386800c6f530fe899217665b92044bebf0a6a4f54f124d36b22ceda11259e35dc78cfb2ef1db6bdd33a57b96ed80e162c770c41
6
+ metadata.gz: a59505448fa9fdbe16e6117c86eb885d3343ece1f6e3ed18dffaa44727f6d99e71f81dc48661d311c8e1524d09c21f9c78e8a9a13d921b7478c3bdae0110891b
7
+ data.tar.gz: ecdfd1fc6b2b159e8991b9d187decc834958f2970bcbef710739b36b09a44409dce0ac425129459f7d5f86236b7f72227bd06d108790ee6e2cfcff5a7a434736
@@ -1,5 +1,8 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 0.1.8 (2018-12-31)
4
+ * add select_media_type method(#16)
5
+
3
6
  ## 0.1.7 (2018-12-30)
4
7
  * Float value validate bugfix (#15)
5
8
 
@@ -1,26 +1,28 @@
1
1
  module OpenAPIParser::MediaTypeSelectable
2
- # select media type by content_type (consider wild card definition)
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
- if (media_type = content[content_type])
10
- return media_type
11
- end
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
- # application/json => [application, json]
14
- splited = content_type.split('/')
11
+ if (media_type = content[content_type])
12
+ return media_type
13
+ end
15
14
 
16
- if (media_type = content["#{splited.first}/*"])
17
- return media_type
18
- end
15
+ # application/json => [application, json]
16
+ splited = content_type.split('/')
19
17
 
20
- if (media_type = content['*/*'])
21
- return media_type
22
- end
18
+ if (media_type = content["#{splited.first}/*"])
19
+ return media_type
20
+ end
23
21
 
24
- nil
25
- end
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, content)
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, content)
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
@@ -1,3 +1,3 @@
1
1
  module OpenAPIParser
2
- VERSION = '0.1.7'.freeze
2
+ VERSION = '0.1.8'.freeze
3
3
  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.7
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-30 00:00:00.000000000 Z
11
+ date: 2018-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler