blueprinter icon indicating copy to clipboard operation
blueprinter copied to clipboard

Hide identifier

Open CarlosUvaSilva opened this issue 4 years ago • 1 comments

is there a way to not send the identifier?

at the moment I'm returning

{
  "data": {
    "id": 7,
    "token": "xxxxxxxxxxxxxxxxx"
  },
  "meta": {}
}

I want to send just

{
  "data": {
    "token": "xxxxxxxxxxxxxxxxx"
  },
  "meta": {}
}

my blueprint looks like this

class UserBlueprinter < Blueprinter::Base
  fields :token

  view :admin_view do
    identifier :id
  end
end

CarlosUvaSilva avatar May 25 '21 13:05 CarlosUvaSilva

Hi @CarlosUvaSilva, I just responded to issue: https://github.com/procore/blueprinter/issues/271

identifier is a purely a developer convenience for being able to create a Blueprinter field that:

  1. Get's added to the default view, and therefore will be included in all renders by default
  2. By default Blueprinter sorts rendered keys by name, however, the identifier field is always sorted as first in the list.

Currently, if you do not want either of the developer convenience behaviors above, the best approach is to simply not use the identifier field, and instead create it as a regular field.

mcclayton avatar Jul 19 '21 21:07 mcclayton