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

How to document dynamic hashes in response? #867

Open
Insood opened this issue Aug 16, 2022 · 0 comments
Open

How to document dynamic hashes in response? #867

Insood opened this issue Aug 16, 2022 · 0 comments

Comments

@Insood
Copy link

Insood commented Aug 16, 2022

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.

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