Skip to content
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

Reworked args on route to be a list so user can describe args function #30

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bbalser
Copy link
Collaborator

@bbalser bbalser commented Nov 16, 2021

is to receive

also cleaned up test helpers

@@ -47,6 +47,7 @@ defmodule Maverick.Api do
@otp_app Keyword.fetch!(opts, :otp_app)
@root_scope opts |> Keyword.get(:root_scope, "/")
@router Module.concat(__MODULE__, Router)
@modules opts |> Keyword.get(:modules, [])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know why i have the opts inside the parens on line 47 but i'm piping them in on line 48; i'd just get rid of all of those single-pipes, no idea what i was thinking

@@ -1,7 +1,7 @@
defmodule Maverick.TestRoute1 do
use Maverick, scope: "/route1"

@route path: "multiply", args: {:required_params, [:num1, :num2]}, error: 403
@route path: "multiply", args: [:params], error: 403
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is transitional until you get to the more explicit "required non-nil values" you mentioned?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, want to get basic argument handling done, and then come back and add required params.

defp arg(conn, :conn), do: conn

defp arg(conn, {parameter, :required}) do
get_in(conn.params, List.wrap(parameter))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the same as the non-required version below; should this blow up if the get_in fails?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I forgot I had this in there, I will pull it out of this PR and deal with required params later.

Comment on lines +2 to +4
def validate(args) do
args
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

placeholder?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

|> :application.get_key(:modules)
@spec list_routes(Maverick.api(), Maverick.root_scope()) :: [t()]
def list_routes(api, root_scope) do
api.list_modules()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch; this will help prevent really big apps from searching through hundreds to thousands of modules

Copy link
Owner

@jeffgrunewald jeffgrunewald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved unless this particular branch is still WIP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants