Skip to content

Supporting nested schemas #41

Open
@brettz9

Description

@brettz9

Not sure how tricky this would end up being, but it would be nice to have support for a hierarchy of types such that something like:

const schemas = {
  $defs: {
    Person: {
      title: 'Person',
      type: 'object',
      properties: {
        name: { type: 'string', description: "A person's name" },
        age: { type: 'integer', description: "A person's age" }
      },
      required: ['name']
    },
    Laborer: {
      title: 'Laborer',
      allOf: [
        {$ref: '#/$defs/Person'},
        {type: 'object', properties: {skillLevel: {type: 'integer'}}},
      ]
    }
  }
}

...could get mapped to:

/**
 * @typedef {PlainObject} Person
 * @property {string} name A person's name
 * @property {integer} [age] A person's age
 */

/**
 * @typedef {Person} Laborer
 * @property {integer} [skillLevel]
 */

(Note how Laborer inherits from Person in the type portion of the Laborer @typedef.)

(I'm using $defs which is the latest JSON Schema draft's equivalent for what had been definitions.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions