Search code examples
node.jsstronglooploopbackloopback4

How can I use a property in a model in Loopback 4 (strongloop) and hide it in the /explorer (Ej: Autogenerated ID)


I have this model done in loopback 4:

@property({
    type: 'string',
    id: true,
    default: () => uuid(),
  })

  id: string;

  @property({
    type: 'string',
    required: true,
  })
  name: string;

As you see, the id is generated by default. But in the loopback/explorer

image explorer

The id appears. I want to hide it, if is going to be auto generated, It could produce a confusion to the developers that want to use this API. Anybody knows how to put a property in a model, and hide it from the /explorer ?

Thanks.


Solution

  • Just exclude the id from the request body schema

    @requestBody({
          content: {
            'application/json': {
              schema: getModelSchemaRef(Model, {exclude: ['id']}),
            },
          },
        }
    

    Hope this helps Thanks