How to document dynamic hashes in response?
Insood opened this issue · comments
Gary commented
Hello,
I have this scenario:
- I have an existing Grape endpoint that's something like
GET /user/:id/settings
that is consumed by a UI - The endpoint presents some entity that looks like:
{
"foo": "bar",
"columns": {
"A" : {
"enabled": true,
"description": "foo"
},
"B" : {
"enabled": false,
"description": "bar"
}
}
}
- I cannot figure out how to programmatically show the documentation for the
columns
entities using grape. I've tried
class Setting < Grape::Entity
expose [...]
expose :columns, using: ColumnSetting do |setting|
setting.column_settings # Function call that returns a hash of { "label" => hash that can be displayed as a ColumnSetting }
end
end
-- I've tried options like additional_properties
, but that is apparently only available on the params side, not on the response side.
Any suggestions? The "correct" thing to do seems to be that columns
should've been an array of ColumnSettings where the label is a property of ColumnSetting, but this pattern already exists across multiple endpoints and can't be changed.