Skip to content

How to do inheritance? #348

Closed
Closed
@kiloquad

Description

@kiloquad

Sorry, I can't find any better place to ask and I can't find any examples. It looks like $merge would do it but according to issue #15, this wont be included.

My use case, I have an Person object in a schema file with a firstName and lastName requires firstName.

I need an Employee object in a separate schema. I want it to inherit Person and add the property company and require the company property.

A valid Person:

{
  "firstName": "Bob",
  "lastName": "Smith"
}

An invalid Person:

{
  "firstName": "Bob"
}

A invalid Person:

{
  "firstName": "Bob",
  "lastName": "Smith",
  "foo": "bar"
}

A valid Employee:

{
  "firstName": "Bob",
  "lastName": "Smith",
  "company": "ABC Inc."
}

An invalid Employee:

{
  "firstName": "Bob",
  "lastName": "Smith",
  "company": "ABC Inc.",
  "foo": "bar"
}

A invalid Employee:

{
  "firstName": "Bob",
  "company": "ABC Inc."
}

I'd like to end up with two schema files, Person.schema.json and Employee.schema.json. Where a Person object or and Employee object would pass Person.schema.json validation, a Person object would not necessarily pass Employee.schema.json validation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions