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

Multilevel scope parameters #176

Closed
ghost opened this issue Nov 17, 2014 · 6 comments
Closed

Multilevel scope parameters #176

ghost opened this issue Nov 17, 2014 · 6 comments

Comments

@ghost
Copy link

ghost commented Nov 17, 2014

Hi, just trying to make multilevel scope parameters but I am unable to make it using scope_parameters.
an example code could be:

parameter :item_id, "Id of an item to order", required: true
parameter :city, "Address city", required: true

scope_parameters :order, [
  :item_id,
  address: [
    :city
  ]
]

Is there a way to define them or is it a feature request?

@ghost
Copy link
Author

ghost commented Nov 17, 2014

I can always define the address as param and send it as an object something like

let(:address) {{
  city: 'London'
}}

But I would like to have the nested param defined in API documentation as well.

@oestrich
Copy link
Contributor

scope_parameters is no longer a DSL method. It also never worked how you're trying. I don't think multiple levels is supported at the moment. For item_id you can do:

parameter :item_id, "...", :scope => :order

@ghost
Copy link
Author

ghost commented Nov 17, 2014

Ah good to know. I wasn't sure how it works as I couldn't find any answer (obviously, was never implemented). Shall we leave this open then as a feature request, btw? I do nested params quite often as it's an Ember way and defined in JSON:API standards. Grape API supports it as well.

@oestrich
Copy link
Contributor

Documenting it nicely won't work at the moment, that's half of what the :scope key does. To get it going without nicer documentation you can override the post body completely.

ley(:raw_post) do
  {
    :order => {
      :item_id => item_id,
      :address => {
        :city => city,
      },
    },
  }
end

@ghost
Copy link
Author

ghost commented Nov 18, 2014

Yeah, We able to define the address.city without using a :raw_post as the address param can be scoped to :order and can be an object. Why I raised this issue was mainly to point out that I am unable to document 2nd+ level nested params.

@oestrich
Copy link
Contributor

Closed with #221

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

No branches or pull requests

1 participant