ruby-grape / grape-swagger

Add OAPI/swagger v2.0 compliant documentation to your grape API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

drewnichols opened this issue · comments

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