ruby-grape / ruby-grape/grape-swagger

is there a simple way to hide attributes that would only show up in the response from the request example?

Open
#866 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
1.1k
Forks
479
Avg merge
2d 14h
Merged PRs (30d)
6

Description

Example grape resource:

  class MyResource < Grape::API
    resource :my_resource do
      desc 'My Resource' do
        params MyResourceEntity.documentation
        success model: MyResourceEntity
      end
    ....
    end
  end

  class MyResourceEntity < Grape::Entity
    expose :my_resource_id, 
           documentation: {
             type: String,
             desc: 'Unique identifier of MyResource generated wtih response',
             required: false,
             example: SecureRandom.uuid
           }
    expose :my_resource_value, 
           documentation: {
             type: String,
             desc: 'A required parameter fo MyResource',
             required: true,
             example: "some value"
           }
  end

With this setup we get the following sample request and response:

{ 
  "my_resource_id": "c210b0e9-583d-4587-8e2a-51f683892187",
  "my_resource_value": "some value"
}

I'd like to hide the my_resource_id from the request because it's generated by the API once the resources model is created. This would make the request and response look like this:

Request

{ 
  "my_resource_value": "some value"
}

Response

{ 
  "my_resource_id": "c210b0e9-583d-4587-8e2a-51f683892187",
  "my_resource_value": "some value"
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing how Grape::Entity documentation and the success model produce request and response examples. The change is complete when generated requests omit response-only fields such as my_resource_id while responses continue to include them.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, documentation
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.