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

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

Open
drewnichols opened this issue Aug 3, 2022 · 0 comments

Comments

@drewnichols
Copy link

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