openapi_first 3.4.2 → 3.4.3

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: ecc348b6dd46b9809fd954f64089ab3bf734274b74983789dc8f79e81db042dc
4
- data.tar.gz: e0f876e897f84d454a9f176d340690ee0a1e3a73b398500704619a8dec0a8142
3
+ metadata.gz: aa35ee9098e786a73c8d0de102d691cb0f5cec972e60e9a8d96d439f63eef872
4
+ data.tar.gz: b6f8461c433753a49563055b4fd3156cbbacf0c89d5f7e2f2a7f1366c2c3b32c
5
5
  SHA512:
6
- metadata.gz: 337b9f7426bcc67fdf582c100c3db967db369e55795fa92f6b0e4418d44dc4846e63b5806972b81e735b5aae104592e553fb91ac17f2f21fcec91b5763a1c8a3
7
- data.tar.gz: 67d8b129a9d9f89038b6d8d4698163009bf934b910fe13ba815c86136e8465acbdd90ea8f105e9e1811bd4d7778e4d87db96af8db880e15fbf2077bf5f6f558d
6
+ metadata.gz: 2146d351211ebc10237dd8f6d30381d15d99ac15bf0cfa05a9095b6f493738b48c4e406b0d359fcc6f11c9910702b0e3ad4003b6513d32cd2390c81a356fd21b
7
+ data.tar.gz: 2235965c286c2d182a77b491422c18a25010f69c0e91e87e50731334aa5515fdbe3cd06d03a4a509c3f07b07f1405a928b50a6b037ed022fc0dd3b60e8bf1be9
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.4.3
6
+
7
+ Fixed: Loading a document no longer raises `NoMethodError: undefined method 'schema' for nil` when a Media Type Object has no `schema` (e.g. it only declares an `example`). `schema` is optional in a Media Type Object; such media types now impose no body-schema constraint.
8
+
5
9
  ## 3.4.2
6
10
 
7
11
  Fixed: Parsing of JSON-formatted query params [issue #476](https://github.com/ahx/openapi_first/issues/476) (thanks @Drowze)
@@ -140,7 +140,7 @@ module OpenapiFirst
140
140
  end
141
141
  required_body = operation_object['requestBody']&.resolved&.fetch('required', false) == true
142
142
  content_objects.map do |content_type, content_object|
143
- content_schema = content_object['schema'].schema(
143
+ content_schema = content_object['schema']&.schema(
144
144
  configuration: schemer_configuration,
145
145
  after_property_validation: config.after_request_body_property_validation
146
146
  )
@@ -171,7 +171,7 @@ module OpenapiFirst
171
171
  responses.flat_map do |status, response_object|
172
172
  headers = build_response_headers(response_object['headers'])
173
173
  response_object['content']&.map do |content_type, content_object|
174
- content_schema = content_object['schema'].schema(
174
+ content_schema = content_object['schema']&.schema(
175
175
  configuration: schemer_configuration,
176
176
  after_property_validation: config.after_response_body_property_validation
177
177
  )
@@ -54,9 +54,6 @@ module OpenapiFirst
54
54
  @operation['operationId']
55
55
  end
56
56
 
57
- MULTIPART_CONTENT_TYPE = %r{\Amultipart/form-data\b}i
58
- private_constant :MULTIPART_CONTENT_TYPE
59
-
60
57
  private
61
58
 
62
59
  def parse_request(request, route_params:)
@@ -82,11 +79,7 @@ module OpenapiFirst
82
79
  end
83
80
 
84
81
  def build_body_parser(content_type, encoding)
85
- if content_type.match?(MULTIPART_CONTENT_TYPE)
86
- RequestBodyParsers::MultipartBodyParser.new(encoding: encoding || {})
87
- else
88
- RequestBodyParsers[content_type]
89
- end
82
+ RequestBodyParsers[content_type, { encoding: encoding || {} }]
90
83
  end
91
84
  end
92
85
  end
@@ -14,9 +14,12 @@ module OpenapiFirst
14
14
  parsers[pattern] = parser
15
15
  end
16
16
 
17
- def [](content_type)
17
+ def [](content_type, options = {})
18
18
  key = parsers.keys.find { content_type.match?(_1) }
19
- parsers.fetch(key) { DEFAULT }
19
+ parser = parsers.fetch(key) { DEFAULT }
20
+ return parser.new(options) if parser.is_a?(Class)
21
+
22
+ parser
20
23
  end
21
24
  end
22
25
 
@@ -44,12 +47,8 @@ module OpenapiFirst
44
47
  # `contentType: application/json` (or any */json), the field's raw value
45
48
  # is JSON-parsed before schema validation.
46
49
  class MultipartBodyParser
47
- def initialize(encoding: {})
48
- @encoding = encoding || {}
49
- end
50
-
51
- def self.call(request)
52
- new.call(request)
50
+ def initialize(options)
51
+ @encoding = options[:encoding] || {}
53
52
  end
54
53
 
55
54
  def call(request)
@@ -89,7 +88,7 @@ module OpenapiFirst
89
88
  end
90
89
  end
91
90
 
92
- register('multipart/form-data', MultipartBodyParser)
91
+ register(%r{\Amultipart/form-data\b}i, MultipartBodyParser)
93
92
 
94
93
  register('application/x-www-form-urlencoded', lambda(&:POST))
95
94
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiFirst
4
- VERSION = '3.4.2'
4
+ VERSION = '3.4.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_first
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.2
4
+ version: 3.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Haller