Merge branch 'fix/empty-params-openapi' into 'develop'
authorrinpatch <rinpatch@sdf.org>
Sat, 3 Oct 2020 12:35:49 +0000 (12:35 +0000)
committerrinpatch <rinpatch@sdf.org>
Sat, 3 Oct 2020 12:35:49 +0000 (12:35 +0000)
OpenAPI CastAndValidate: filter out empty params

Closes #2198

See merge request pleroma/pleroma!3047

CHANGELOG.md
lib/pleroma/web/api_spec/cast_and_validate.ex

index e02e843011fae4ca83dddaa1ebcfc9979cabe3c6..213467d6e7b961467f9d5dcf410df5d860bb98ea 100644 (file)
@@ -39,6 +39,11 @@ switched to a new configuration mechanism, however it was not officially removed
 - Add documented-but-missing chat pagination.
 - Allow sending out emails again.
 
+## Unreleased (Patch)
+
+### Changed
+- API: Empty parameter values for integer parameters are now ignored in non-strict validaton mode.
+
 ## [2.1.2] - 2020-09-17
 
 ### Security
index fbfc27d6f7655cd3efe38556c9e3c706421a6081..6d1a7ebbcc0a329f31d34f10e34e33574b8c98e2 100644 (file)
@@ -115,6 +115,10 @@ defmodule Pleroma.Web.ApiSpec.CastAndValidate do
             %{reason: :unexpected_field, name: name, path: [name]}, params ->
               Map.delete(params, name)
 
+            # Filter out empty params
+            %{reason: :invalid_type, path: [name_atom], value: ""}, params ->
+              Map.delete(params, to_string(name_atom))
+
             %{reason: :invalid_enum, name: nil, path: path, value: value}, params ->
               path = path |> Enum.reverse() |> tl() |> Enum.reverse() |> list_items_to_string()
               update_in(params, path, &List.delete(&1, value))