Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Sharing params #23

Open
mmcc opened this issue Jun 27, 2017 · 1 comment
Open

Sharing params #23

mmcc opened this issue Jun 27, 2017 · 1 comment

Comments

@mmcc
Copy link

mmcc commented Jun 27, 2017

We have quite a few query parameters that are shared across many routes, so it makes a lot of sense for us to share as much as we can there. I've tried a few different routes, but my metaprogramming-fu does not seem to be up to the challenge. Is this possible or am I just doing it wrong?

Here's what I've attempted so far:

# Shared parameters
def shared_list_params do
  quote do
    parameter :timeframe, :array, [description: "Timeframe array or duration string.", example: "24:hours"]
    parameter :page, :number, [optional: true, default: 1, example: 1]
    parameter :order_by, :string, [description: "Value to order the results by", default: "negative_impact"]
    parameter :order_direction, :string, [members: ["asc", "desc"]]
    parameter :limit, :number, [default: 100]
  end
end

api :GET, "/v1/something" do
  title "List somethings"
  description "Returns a whole lot of something"

  # Attempt 1
  unquote(shared_list_params())

  # Attempt 2
  Code.eval_quoted(shared_list_params())
end

Neither of these blew up, but they didn't work, either. Any ideas on how to achieve something like this while using the api macro?

@woylie
Copy link
Contributor

woylie commented Jun 28, 2017

I did some experimenting and found a way to do it, but not without changing the original api/2 macro. Please have a look at PR #24 and let me know what you think.

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

No branches or pull requests

2 participants