@@ -69,7 +69,6 @@ defmodule OpenApiSpex.CastParameters do
69
69
properties: parameters |> Map . new ( fn p -> { p . name , Parameter . schema ( p ) } end ) ,
70
70
required: parameters |> Enum . filter ( & & 1 . required ) |> Enum . map ( & & 1 . name )
71
71
}
72
- # |> maybe_combine_oneOfs(parameters, components)
73
72
|> maybe_add_additional_properties ( components ) ,
74
73
parameters_contexts ( parameters )
75
74
}
@@ -141,7 +140,23 @@ defmodule OpenApiSpex.CastParameters do
141
140
# fields in parameters and combine the parameters in a single struct
142
141
# so that the casting can do further work
143
142
defp maybe_combine_params ( % { } = parameters , % { } = schema , % { } = parameters_contexts ) do
144
- Enum . reduce ( parameters_contexts , parameters , fn
143
+ # first filter out from parameters fields that match non exploding properties.
144
+ # we do this because we want to keep the original parameters struct intact
145
+ # and not remove fields that are not part of the exploding property
146
+
147
+ non_exploding_matches = Enum . reduce ( parameters , Map . new ( ) , fn { key , value } , acc ->
148
+ case Map . get ( parameters_contexts , key , % { } ) do
149
+ % { explode: false } ->
150
+ Map . put ( acc , key , value )
151
+
152
+ _ ->
153
+ acc
154
+ end
155
+ end )
156
+
157
+ possible_exploding_matches = Enum . reject ( parameters , & Enum . member? ( non_exploding_matches , & 1 ) ) |> Map . new ( )
158
+
159
+ combined_params = Enum . reduce ( parameters_contexts , possible_exploding_matches , fn
145
160
{ key , % { explode: true } } , parameters ->
146
161
# we have exploding property, we need to search for it's possible fields
147
162
# and add them under the key into the parameters struct.
@@ -153,18 +168,15 @@ defmodule OpenApiSpex.CastParameters do
153
168
Schema . possible_properties ( schema_of_exploding_property )
154
169
155
170
{ struct_params , found_keys } =
156
- Enum . reduce ( fields , { Map . new ( ) , [ ] } , fn { field_key , _ } , { struct_params , found_keys } ->
171
+ Enum . reduce ( fields , { Map . new ( ) , [ ] } , fn { field_key , _default } , { struct_params , found_keys } ->
157
172
param_field_key = field_key |> Atom . to_string ( )
158
173
val = Map . get ( parameters , param_field_key )
159
174
160
- { new_params , new_found_keys } =
161
175
unless is_nil ( val ) do
162
176
{ Map . put ( struct_params , param_field_key , val ) , [ param_field_key | found_keys ] }
163
177
else
164
178
{ struct_params , found_keys }
165
179
end
166
-
167
- { new_params , new_found_keys }
168
180
end )
169
181
170
182
parameters
@@ -174,6 +186,8 @@ defmodule OpenApiSpex.CastParameters do
174
186
_ , parameters ->
175
187
parameters
176
188
end )
189
+
190
+ Map . merge ( non_exploding_matches , combined_params )
177
191
end
178
192
179
193
defp pre_parse_parameters ( % { } = parameters , % { } = parameters_context , parsers ) do
@@ -250,20 +264,4 @@ defmodule OpenApiSpex.CastParameters do
250
264
_ -> schema
251
265
end
252
266
end
253
-
254
- defp maybe_combine_oneOfs ( schema , parameters , components ) do
255
- # check if any params have explode,
256
- # if so add the properties of it's schema to the top level
257
- # and remove the key for that
258
- % { }
259
- end
260
-
261
- defp create_one_of_schemas ( parameters ) do
262
- if Enum . any? ( parameters , fn p ->
263
- p . explode == true and is_list ( Parameter . schema ( p ) . oneOf )
264
- end ) do
265
- # in this case we need to create multiple schemas. Each of the schemas
266
- # has to have properties defined in other parameters + add required properties
267
- end
268
- end
269
267
end
0 commit comments