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

Coerce function with anyOf sub-schemas #204

Closed
nokome opened this issue Aug 5, 2019 · 1 comment · Fixed by #208
Closed

Coerce function with anyOf sub-schemas #204

nokome opened this issue Aug 5, 2019 · 1 comment · Fixed by #208

Comments

@nokome
Copy link
Member

nokome commented Aug 5, 2019

When using Encoda to generate documentation for Schema, @beneboy and I have noticed the followed error message (here replicated using the CLI):

./encoda coerce test.json --from json -

🚨 ERROR encoda /content/1 should have required property 'content'
  Error: /content/1 should have required property 'content'

where test.json is

{
  "type": "Paragraph",
  "content": [
    "The following content has extra ",
    {
      "type": "Emphasis",
      "content": ["emphasis"]
    },
    "."
  ]
}

I turns out that this is related to what is referred to as a bug here:

it('currently has a bug with arrays using anyOf', async () => {
const article = await coerce(
{
title: 'Untitled',
authors: [
{
givenNames: ['Joe']
},
{
// Even though we explicitly state that this is an
// `Organization`, `legalName` gets dropped because
// Ajv sees it as an additional property for `Person`
// This is a bug in Ajv.
type: 'Organization',
name: 'Example Uni',
legalName: 'Example University Inc.'
}
]
},
'Article'
)

But which is apparently not a bug, but rather expected behaviour from using Ajv's removeAdditional: true option:

The proposed solution to this is to not use the removeAdditional option - which will mean coerce will coerce what it can but will not cause the loss of any data - which is probably consistent with our approach elsewhere. If users want to persist additional data then the best place to put that is in Enity.meta

@stencila-ci
Copy link
Collaborator

🎉 This issue has been resolved in version 0.62.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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