2

The loopback docs indicate how to validate models in the REST layer. But, is there a way you can validate deep/nested models inside your model?

If a User has both a name and a Contact, I want both to be validated, including all properties defined in Contact.

This comment from 2015 mentions deep validation is not supported. Is this still the case?

In this more recent answer it is suggested to set type: Contact directly, but I'm getting this error:

Property User.contact does not have "type" in its definition
import {Entity, model, property} from '@loopback/repository';

// User
@model()
export class User extends Entity {
  @property({
    type: 'string',
    required: true,
  })
  name: string;

  @property({
    type: Contact, 
    required: true,
  })
  contact: Contact;
}

// Contact
@model()
export class Contact extends Model {
  @property({
    type: 'string',
    required: true,
    default: 'phone',
  })
  type: string;
}
Carlos Torres
  • 419
  • 2
  • 9
  • 19

0 Answers0