ruby-grape / ruby-grape/grape-swagger
How to document dynamic hashes in response?
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 1.1k
- Forks
- 479
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 6
Description
Hello,
I have this scenario:
- I have an existing Grape endpoint that's something like
GET /user/:id/settingsthat 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
columnsentities 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is identified in the issue. Start by locating the response-side schema generation for Grape entities and how dynamic hash properties are represented; done means the existing columns hash shape is documented without changing the endpoint response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api, documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100