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

Allow empty "required" array #69

Closed
gibson042 opened this issue Oct 2, 2016 · 14 comments
Closed

Allow empty "required" array #69

gibson042 opened this issue Oct 2, 2016 · 14 comments
Milestone

Comments

@gibson042
Copy link
Contributor

(copied from json-schema/json-schema#232 )

Draft v4 specifies that a required array "MUST have at least one element", which makes it impossible to explicitly indicate that all properties are optional (and therefore also impossible to distinguish intentional optionality from accidental omission of required). Empty values ("required": []) should be permitted.

@erosb
Copy link

erosb commented Oct 2, 2016

which makes it impossible to explicitly indicate that all properties are optional

I don't think it is a problem. Being able to express the same thing in multiple ways (an explicit and an implicit notation) is not a goal of the specification.

@gibson042
Copy link
Contributor Author

Then why is there an integer type, to point out just one from a multitude of counterexamples? And why not make required required, so author intention is always clear?

Put another way, the default value of minItems is 0. Why deviate from that default for required?

@erosb
Copy link

erosb commented Oct 2, 2016

And why not make required required, so author intention is always clear?

That should be a different proposal.

@gibson042
Copy link
Contributor Author

I was pointing out the inconsistency in claiming that JSON Schema is good about preventing multiple ways of expressing the same thing, not seriously suggesting requiring required. This (allowing required: []) is the serious proposal, because an empty value conveys information that is not possible if the property is absent (and in fact I've begun defining schemas with _required: [] as a workaround).

@awwright
Copy link
Member

awwright commented Oct 8, 2016

I would personally try to leave out a keyword if it's not going to have any effect on validation (since keywords generally add constraints to an instance), but not being overly pedantic about these sorts of things seems pretty reasonable.

There might be a good reason to want to leave in a keyword even if it's not going to do anything.

@handrews
Copy link
Contributor

handrews commented Oct 8, 2016

I agree with @awwright about trying to leave it out, but as long as required doesn't become required (no keyword should be required, as {} should always be valid and validate everything) I like the idea of allowing "required": []

I think mostly we allow putting in the default explicitly, so required is currently an exception to that pattern.

@Relequestual
Copy link
Member

If it says in the spec, that if required is not included, then all are optional, then I don't see that there's a problem.

@epoberezkin
Copy link
Member

No objection here to allowing required: [], it's backward compatible :)...

@awwright awwright added this to the draft-6 milestone Oct 11, 2016
handrews added a commit to handrews/json-schema-spec that referenced this issue Oct 28, 2016
This addresses the enhancement requested in issue json-schema-org#69.
handrews added a commit to handrews/json-schema-spec that referenced this issue Nov 8, 2016
This addresses the enhancement requested in issue json-schema-org#69.
@awwright
Copy link
Member

Er, as I mentioned in #112, it turns out "dependencies" has this behavior too.

I'd like to just modify "stringArray" so both "dependencies" properties and "required" allows multiple items. They're both used for the same purpose, we should probably modify this behavior together.

handrews added a commit to handrews/json-schema-spec that referenced this issue Nov 15, 2016
This addresses the enhancement requested in issue json-schema-org#69.

The "requirements" and "dependencies" string arrays should be
allowed to be empty, with the same effect as not being present.
@handrews
Copy link
Contributor

@gibson042 with #112 now merged (thanks, @awwright !) I think this is now fixed. If you agree could you please close?

@epoberezkin
Copy link
Member

In parallel with other keywords in I-D (minLength, etc.), it can be said that {"required":[]} is equivalent to {}, so [] is default for required.

@awwright
Copy link
Member

Good point, I'll reopen this briefly so I don't forget

@awwright
Copy link
Member

Addressed in #171

@handrews
Copy link
Contributor

@awwright I already included this fix in #168 with all the other meta-schema stuff.

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

No branches or pull requests

6 participants