Apipie / apipie-rails

Ruby on Rails API documentation tool
Apache License 2.0
2.47k stars 462 forks source link

How to define Rails' has_many attributes? #245

Open lazywei opened 10 years ago

lazywei commented 10 years ago

Hi there,

In Rails, I can use

has_many :apps
accepts_nested_attributes_for :apps

and then pass parameters to controller

{ ..., "apps_attributes": [ {"name": "hello", ...}, ... ] }

How can I define params for such use case?

Must I define like this?

param :apps_attributes

And, how to define array? The document for Array Validator seems not for such case.

Thanks.

lazywei commented 10 years ago

I found that #229 and #230 seems to be created for such use case.

I tried:

param :store do
  ...
  param :apps_attributes, Array do
    param :description
  end
end

and in document:

store[apps_attributes]
Value: Must be an Array of nested elements

store[apps_attributes][description] 
Value: Must be String

store[apps_attributes][description] seems a little confusing. If I saw some docs like this, I may misunderstand it, and pass parameter likes ... {"apps_attributes": {"description: ... }} ..., which is definitely wrong.

iNecas commented 10 years ago

Yeah, We had first just a nested hash support, and added the arrays there later, but keeping the same way how we display the stuff. I'm not sure which would be the best solution to this …