0

I am making a fairly large json-schema (draft 4) and want all properties to be required, without having to add each property to the required array. Is it possible to set all properties as required by default?

Matthew Moisen
  • 16,701
  • 27
  • 128
  • 231
  • Possible duplicate of [JSON Schema - require all properties](https://stackoverflow.com/questions/30868023/json-schema-require-all-properties) – Gamora Sep 04 '19 at 15:21
  • A better (in my opinion) work around than below, in case anyone else comes across this answer :) – Gamora Sep 04 '19 at 15:22

1 Answers1

2

There is nothing in json-schema that would make properties required by default.

If manually generating the list of properties is problematic, I would suggest the following.

  1. Define a new keyword that adds the functionality you desire.
  2. Write your schemas using your new keyword.
  3. Write a function that takes an extended json-schema and returns a standard json-schema.
  4. Use the generated standard schemas in your favorite json-schema validator.

This approach allows you to write your schemas in the most convenient way for you while still being able to use standard tools. If you think your extension could be useful to others, you can also propose it be added to the next draft of the json-schema specification.

Jason Desrosiers
  • 22,479
  • 5
  • 47
  • 53