@@ -139,8 +139,8 @@ defmodule OpenApiSpex.Operation do
139
139
"""
140
140
@ spec response (
141
141
description :: String . t ( ) ,
142
- media_type :: String . t ( ) | % { String . t ( ) => Keyword . t ( ) | MediaType . t ( ) } ,
143
- schema_ref :: Schema . t ( ) | Reference . t ( ) | module ,
142
+ media_type :: String . t ( ) | % { String . t ( ) => Keyword . t ( ) | MediaType . t ( ) } | nil ,
143
+ schema_ref :: Schema . t ( ) | Reference . t ( ) | module | nil ,
144
144
opts :: keyword
145
145
) :: Response . t ( )
146
146
def response ( description , media_type , schema_ref , opts \\ [ ] ) do
@@ -158,7 +158,7 @@ defmodule OpenApiSpex.Operation do
158
158
% Response {
159
159
description: description ,
160
160
headers: opts [ :headers ] ,
161
- content: build_content_map ( media_type , content_opts )
161
+ content: build_response_content_map ( media_type , content_opts )
162
162
}
163
163
end
164
164
@@ -303,6 +303,11 @@ defmodule OpenApiSpex.Operation do
303
303
|> Schema . validate ( params , schemas )
304
304
end
305
305
306
+ defp build_response_content_map ( nil , _media_type_opts ) , do: nil
307
+
308
+ defp build_response_content_map ( media_type , media_type_opts ) ,
309
+ do: build_content_map ( media_type , media_type_opts )
310
+
306
311
defp build_content_map ( media_type , media_type_opts ) when is_binary ( media_type ) do
307
312
% {
308
313
media_type => struct! ( MediaType , media_type_opts )
@@ -317,6 +322,6 @@ defmodule OpenApiSpex.Operation do
317
322
end
318
323
319
324
defp build_content_map ( media_types , _shared_opts ) do
320
- raise "Expected string or map for request_body : #{ inspect ( media_types ) } "
325
+ raise "Expected string or map as a media type. Got : #{ inspect ( media_types ) } "
321
326
end
322
327
end
0 commit comments