Skip to content

✨ Proposal: recommended keyword similar to required #1647

@juanmeleiro

Description

@juanmeleiro

Describe the inspiration for your proposal

I write JSON by hand to store data in lots of my personal projects. Two illustrative examples are keeping journals and storing metadata about books and other media I have in my library. I also use JSON Schemas to make sure I don't mistype anything, and I don't forget any fields.

However, I found in more than one occasion that some fields are not strictly necessary, but are almost always used and their omission almost always is a mistake. This is precisely the semantics of the “SHOULD” keyword such as in RFC 2119 and similar documents.

To my mind, the best behavior a schema checker should have in this situations is to issue a warning (not an error) upon the omission of such a keyword.

Alas, I could not find a feature of JSON schema that would have checkers in the wild issue warnings.

Describe the proposal

I see two possibilities:

  • Add a keyword recommended to object schemas that would have as a value a list of strings. Those strings are keys that SHOULD be present in objects to be matched by the schema, and checkers SHOULD issue a warning if not present.

  • Add a keyword recommended to any schema that would take as a value another schema. If this child schema does not match, then checkers SHOULD issue a warning.

Describe alternatives you've considered

I can't figure out a way to do this with existing checkers and vocabularies. There might be a vocabulary with this feature (or one might be created), but that would require (as far as I understand) extending any single checker with support for that vocabulary.

Additional context

I'm new to this project and I understand that my suggestion my go against some design goal or policy, in which case I understand it might get rejected out of the gate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalInitial discussion of a new idea. A project will be created once a proposal document is created.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions