question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

strictRequired error when required properties exists and are declared inside oneOf

See original GitHub issue

Using version 8.1.0 with strict mode enabled, an error of type strictRequired is thrown when required properties are declared inside oneOf even if those properties are defined next to oneOf.

Ajv options object

const ajv = new Ajv({
  strict: true,
})

JSON Schema

{
  "type": "object",
  "properties": {
    "property_a": {
      "type": "string",
    },
    "property_b": {
      "type": "string",
    },
  },
  "anyOf": [
    { "required": [ "property_a" ] },
    { "required": [ "property_b" ] }
  ]
}

Sample data

{
  property_a: 'ok'
}

Your code

The code posted on runkit throw an error with the message strict mode: required property "property_a" is not defined at "#/anyOf/0" (strictRequired) (after switching from stack trace viewer to properties viewer in the UI)

What results did you expect?

Unless I am misunderstanding something, I expect the code to be valid since property_a is defined inside properties.

Are you going to resolve the issue?

This probably requires a deep understanding of Ajv internals.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
LucasBrazi06commented, Oct 9, 2021

Have you planned a fix for this issue? When?

2reactions
epoberezkincommented, Apr 27, 2021

You’re welcome. Let’s keep it open - it’s a limitation, not the optimal behaviour.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Schema oneof without required - Stack Overflow
[EDITED - SEE THIRD SOLUTION BELOW]. Solution 1 - At least one, but not both (verbose). I would add an allOf with a...
Read more >
Strict mode - Ajv JSON schema validator
With option strictRequired set to "log" or true Ajv logs warning or throws exception if the property used in "required" keyword is not...
Read more >
mod_ssl - Apache HTTP Server Version 2.4
Require ssl-verify-client. The ssl provider allows access if the user is authenticated with a valid client certificate. This is only useful if SSLVerifyClient ......
Read more >
Re: Dependencies between two "enums" - Google Groups
All I have to do in addition is to find out which of the "oneOf" Schemas are actually valid and ... property is...
Read more >
Model | Ts.ED - A Node.js and TypeScript Framework on top of ...
Sometimes, it can be useful to create model with additional properties. By default, Json schema is strict over extra properties not declared in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found