-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CastAndValidate plug does not set Cast.read_write_scope #499
Comments
Something along those lines should fix that issue: diff --git a/lib/open_api_spex/cast.ex b/lib/open_api_spex/cast.ex
index 81b5564..f35d3b4 100644
--- a/lib/open_api_spex/cast.ex
+++ b/lib/open_api_spex/cast.ex
@@ -100,10 +100,21 @@ defmodule OpenApiSpex.Cast do
"""
- @spec cast(schema_or_reference | nil, term(), map(), [cast_opt()]) ::
+ @spec cast(schema_or_reference | nil, term(), map(), [
+ cast_opt() | {:read_write_scope, read_write_scope()}
+ ]) ::
{:ok, term()} | {:error, [Error.t()]}
def cast(schema, value, schemas \\ %{}, opts \\ []) do
- ctx = %__MODULE__{schema: schema, value: value, schemas: schemas, opts: opts}
+ {read_write_scope, opts} = Keyword.pop(opts, :read_write_scope, nil)
+
+ ctx = %__MODULE__{
+ schema: schema,
+ value: value,
+ schemas: schemas,
+ opts: opts,
+ read_write_scope: read_write_scope
+ }
+
cast(ctx)
end
diff --git a/lib/open_api_spex/plug/cast_and_validate.ex b/lib/open_api_spex/plug/cast_and_validate.ex
index e8af40f..ce7fa94 100644
--- a/lib/open_api_spex/plug/cast_and_validate.ex
+++ b/lib/open_api_spex/plug/cast_and_validate.ex
@@ -79,7 +79,13 @@ defmodule OpenApiSpex.Plug.CastAndValidate do
cast_opts = opts |> Map.take([:replace_params]) |> Map.to_list()
- case OpenApiSpex.cast_and_validate(spec, operation, conn, nil, cast_opts) do
+ case OpenApiSpex.cast_and_validate(
+ spec,
+ operation,
+ conn,
+ nil,
+ cast_opts ++ [read_write_scope: :write]
+ ) do
{:ok, conn} ->
conn |
This was referenced Nov 16, 2022
Hi. Is there anything I can do to help to get this fixed? There are two PRs trying to address this issue. Are they missing anything? |
Hi @kaharlichenko, I've merged #572. Please try it out and if it's working for you we can tag a release. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The plug
OpenApiSpex.Plug.CastAndValidate
does not set theOpenApiSpex.Cast.read_write_scope
field.This leads to the plug considering
readOnly
fields to be required in the request body.The text was updated successfully, but these errors were encountered: