Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for draft 2020-12 array syntax #447

Open
JensenLenard opened this issue Aug 9, 2022 · 0 comments
Open

Support for draft 2020-12 array syntax #447

JensenLenard opened this issue Aug 9, 2022 · 0 comments

Comments

@JensenLenard
Copy link

In the latest json schema draft the syntax has changed for arrays and how additional items are being defined.
See: https://json-schema.org/draft/2020-12/release-notes.html

As I did not find an open issue regarding that, I wanted to ask if there is currently work being done to support the new syntax, or if it's still open. Alternatively I wanted to ask if there is a workaround to use this draft version, in case these changes are not wanted for this library.

On a first look through the library it appeared like only this method needed to be changed:

  private addProperty() {
    let itemSchema = this.schema.items
    if (Array.isArray(this.schema.items)) {
      const itemSchemas = this.schema.items as object[]
      if (itemSchemas.length > (<FormProperty[]>this.properties).length) {
        itemSchema = itemSchema[(<FormProperty[]>this.properties).length]
      } else if (this.schema.additionalItems) {
        itemSchema = this.schema.additionalItems
      } else {
        // souldn't add new items since schema is undefined for the item at its position
        return null
      }
    }
    let newProperty = this.formPropertyFactory.createProperty(itemSchema, this);
    (<FormProperty[]>this.properties).push(newProperty);
    return newProperty;
  }

It may be enough to just use "prefixItems" instead of "items" and "items" instead of "additionalItems" to implement the new changes, as it appears that they are effectively just renamed in the new draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant