-
Notifications
You must be signed in to change notification settings - Fork 365
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
How to set diffferent value for same parameter name with different scope? #214
Comments
We're seeing the same issue. We're following the jsonapi spec, which requires related resources to be nested inside a response tag. Example: {
"data":{
"type":"cart-items",
"attributes":{
"count":"1",
"product-iteration-id":2
},
"relationships":{
"product-variant":{
"data": {
"type":"product-variants",
"id":3
}
},
"user":{
"data": {
"type":"users",
"id":4
}
}
}
}
} This leaves us with a problem when creating params, as we would need multiple To illustrate the problem: parameter :id, "Id of product variant", scope: [:relationships, :variant, :data]
parameter :id, "The id of the user (checked against auth token)", scope: [:relationships, :user, :data]
parameter :type, "Id of product variant", scope: [:relationships, :variant, :data]
parameter :type, "Id of product variant", scope: [:relationships, : user, :data] I'm not familiar enough with the internals of rspec_api_documentation to suggest a technical solution, but from a usage perspective it would be nice if we could define the data and parameter together. Something like: parameter [:relationships, :user, :data, :id], "Id of the user", { user.id } |
#221 also takes care of setting parameters with the same name (and different scopes). You just need to prefix the scope:
To set the parameter value it looks for a method called |
Will it work with underscored_names? (I don't see how it will know the difference between scopes and variable_names?) What about "dasherized-names"? We're using strings in our Example: parameter "display-addr", "The address of the shop", required: false, scope: :attributes
let("display-addr") { "Test shop street 1" } |
Yes, it does.
will look for I haven't tried with dasherized names, but if |
Thanks a lot, especially for linking to the relevant code 👍 Btw, this should be documented. If nobody else does it I'll throw in a PR once I've verified how it works for us. |
Suppose I have a nested form and have 'email' field for parent and child model also if I want to pass parameters for two child objects with different email address. Is there a way to do this?
The text was updated successfully, but these errors were encountered: