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.

Add "objectIncluding" / additionalProperties support

See original GitHub issue

I’ve just read in https://github.com/aldeed/meteor-simple-schema/issues/407 that I can define an object as blackbox and add fields that should be required.

Has this behavior changed lately? Because according to the ticket I referenced above, the following code should throw an error, right?

new SimpleSchema({
  test: {
    type: Object,
    blackbox: true,
  },
  'test.foo': {
    type: String,
  },
}).validate({
  test: { bar: 'bar' },
});

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
aldeedcommented, Apr 11, 2018

@SimonSimCity Here’s what I’m thinking:

Borrowing from JSONSchema, add an additionalProperties option for the SimpleSchema constructor. Unlike JSONSchema, it would be false by default for backwards compatibility.

Example of schema requiring a string name and allowing anything else unvalidated:

new SimpleSchema({ name: String }, {
  additionalProperties: true
});

Example of this as a subschema:

const itemSchema = new SimpleSchema({ name: String }, {
  additionalProperties: true
});

new SimpleSchema({
  foo: String,
  items: [itemSchema]
});

Example where all of the additional props have to have string values with at least 2 characters:

new SimpleSchema({ name: String }, {
  additionalProperties: {
    type: String,
    min: 2
  }
});

I think this is the best combination of flexibility and easy implementation.

The proposal in aldeed/meteor-simple-schema#244 goes beyond this and is much harder to implement. I think the additionalProperties approach should be fairly easy, but won’t know for sure until someone gives it a shot.

0reactions
SimonSimCitycommented, Apr 25, 2018

I mentioned this here because you were borrowing a property from JSON Schema, but your implementation would be quite different from it. If you say that you’d borrow it for this use-case I’d also rather use it the way it’s used there in order to avoid confusion. Another option would be not to link it to the JSON Schema.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support for additionalProperties=False · Issue #106 - GitHub
The above code will yield {'age': 4} so it is not really possible to add additional properties that are not defined on the...
Read more >
OpenAPI Specification quick reference
Prevent workflow designers from adding additional arbitrary properties to objects at design time using additionalProperties. Used in: Parameters and response ...
Read more >
Additional Properties - Liquid Technologies
To add the 'additionalProperties' keyword back into the schema you can use the 'Add Properties -> Additional Properties' command from the context menu...
Read more >
Schema allows additional properties
The schema you have defined allows additional properties, either intentionally or unintentionally. In JSON, by default, any object can also accept additional ......
Read more >
Sailpoint Scim
These are the SCIM APIs for SailPoint's on-premise service, IdentityIQ. ... 0 Test App (OAuth Bearer Token)" and click + Add Integration.
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