Skip to content

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

Open

Description

@drewnichols

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"
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions