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.

Fix additionalProperties on nested schemas

See original GitHub issue

When a schema is nested (not on a first level), When the iteration of properties uses an expression

tpl(`if(%s.properties.hasOwnProperty(${property})) continue;`, tpl.schema);

Then a schema is taken from the context of the generated validation function, Then it is a single start point schema. When additoonalProperties is used on a nested level Then it will fail to validate

Example @see utils/index:makeSchema.js

return {
    properties: required.reduce((memo, key) => (
      Object.assign({}, memo, {
        [key]: makeSchema(instance[key])
      })
    ), {}),
    required,
    // other properties should be valid by `false` schema, aka not exist at all
    // additionalProperties: false,
  };

uncomment additionalProperties -> error

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
SebastienEletcommented, Nov 6, 2018

I was trying djv but i will have to bring back ajv because i meet this issue on all my schema 😦

1reaction
Anthropiccommented, Oct 31, 2017

@korzio would this issue be the cause of the following error?

Result from errorHandler:

[ { keyword: 'oneOf',
    dataPath: '.test[0]',
    schemaPath: '#/properties/test/items/oneOf' } ]

From schema:

{
  "id": "ofTest",
  "type": "object",
  "properties": {
    "test": {
      "type": "array",
      "items": {
        "type": "object",
        "oneOf": [
          { "properties": { "alpha": { "type": "string" }}, "additionalProperties": false },
          { "properties": { "beta": { "type": "string" }}, "additionalProperties": false }
        ]
      }
    }
  },
  "required": [
    "test"
  ]
};

With data:

{ "test": [{ "alpha": "a" }]}

The error handlers I have for both ajv and tv4 pass the test with no objects added to the error array.

Read more comments on GitHub >

github_iconTop Results From Across the Web

v2.4+ silently removes additionalProperties from nested objects
Nested object properties are removed from the request body if a properties block is present in the object's schema unless they are ...
Read more >
`additionalProperties` rule in JSON schema is not applied to ...
Is the additionalProperties JSON schema definition only applies to top-level fields and not to any nested level fields?
Read more >
Schema allows additional properties
If you have nested combining operations inside each other (for example, allOf with anyOf nested in the properties), the correct additionalProperties value ...
Read more >
Schema generation rules · GitBook - Goswagger.Io
To map this to go it creates a struct that has fixed names and a custom json ... "additionalProperties": {schema}, Y, Y, Y,...
Read more >
Structuring a complex schema — Understanding JSON ...
Likewise in JSON Schema, for anything but the most trivial schema, ... A schema document that includes embedded schemas is called a Compound...
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