Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

Refactor approach to generating .schema.json from .schema.yaml #41

Closed
nokome opened this issue Apr 10, 2019 · 1 comment
Closed

Refactor approach to generating .schema.json from .schema.yaml #41

nokome opened this issue Apr 10, 2019 · 1 comment
Assignees
Labels
enhancement New feature or request released

Comments

@nokome
Copy link
Member

nokome commented Apr 10, 2019

JSON Schema doesn't have good support for inheritance (i.e. extending/overriding properties defined in other schemas). There are several problems that arise from our current use of the allOf approach:

  • it's more complicated than it should be to author schemas that extend others
  • well know problem of not being able to specify additionalProperties: false
  • can't override the type property with another constants e.g. CreativeWork can't override Thing
  • the generated Typescript definitions are suboptimal (require defensive programming) because of the above
  • base type and inherited property information is not available for generating docs

The proposed solution is to introduce a $extends keyword and do pre-processing to merge the properties of the base and current types. This would include auto-population of some fields to make schema authoring less tedious and error prone and to add information for docs generation:

  • $schema - always http://json-schema.org/draft-07/schema#
  • $id - populated with https://stencila.github.com/schema/${schema.title}.schema.json
  • properties.type.enum - populated with [${schema.title}]
  • properties - merged from the base and current
  • properties.*.inherited - populated with title of type that they were inherited from
  • required - merged from the base and current and type added
  • additionalProperties: false - if not specified
@nokome nokome added the enhancement New feature or request label Apr 10, 2019
@nokome nokome self-assigned this Apr 10, 2019
@nokome nokome closed this as completed in 516c7bb Apr 11, 2019
@stencila-ci
Copy link
Collaborator

🎉 This issue has been resolved in version 0.9.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request released
Projects
None yet
Development

No branches or pull requests

2 participants