This means the key for the openapi spec needs to have [] at the end of array parameters, otherwise clients generated from the openapi.json file will be using the incorrect name in requests (i.e. files instead of files[]).
Plug's param parsing happens before the CastAndValidate plug, so the plug sees files where the user actually provided files[] in the request.
How can this be handled?
One option could be to add a parsed_param_name option to Schema, and use that to cast/validate. Users would then have to provide parsed_param_name: "files" in this scenario. Maybe there's a way to automatically derive the parsed name from the key name.
Another option is to strip [] from the end of key names in the cast/validate plug. This is what the solution provided by @christmoore is doing in https://github.com/open-api-spex/open_api_spex/issues/441#issuecomment-1095288320 (thanks for that @christmoore!). It wouldn't be possible to support replace_params: true with this approach though.
Adds a failing spec for the issue described in https://github.com/open-api-spex/open_api_spex/issues/441
Array parameters need to be supplied with
[]
on the end of the parameter name, because plug won't parse them into lists without it:This means the key for the openapi spec needs to have
[]
at the end of array parameters, otherwise clients generated from the openapi.json file will be using the incorrect name in requests (i.e.files
instead offiles[]
).Plug's param parsing happens before the CastAndValidate plug, so the plug sees
files
where the user actually providedfiles[]
in the request.How can this be handled?
One option could be to add a
parsed_param_name
option toSchema
, and use that to cast/validate. Users would then have to provideparsed_param_name: "files"
in this scenario. Maybe there's a way to automatically derive the parsed name from the key name.Another option is to strip
[]
from the end of key names in the cast/validate plug. This is what the solution provided by @christmoore is doing in https://github.com/open-api-spex/open_api_spex/issues/441#issuecomment-1095288320 (thanks for that @christmoore!). It wouldn't be possible to supportreplace_params: true
with this approach though.