rest-guide icon indicating copy to clipboard operation
rest-guide copied to clipboard

Required properties should be explicitly defined

Open pvdbosch opened this issue 2 years ago • 1 comments

I often find that the names of properties used in the "required" array haven't been kept in sync with their defined names.

For example:

type: object
properties:
  nameNew:
     type: string
required: [nameOld]

To avoid this, we could define a rule that required properties MUST be explicitly listed in the object's properties (or in a referenced schema within an allOf or the like).

Strictly, according to JSON Schema, specifying the property is not required; it would be a required property then without content restriction. It is still possible to list it then in the object's properties without a type.

pvdbosch avatar Dec 11 '23 10:12 pvdbosch

WG is okay to add this new rule, I'll work out a PR.

pvdbosch avatar Jan 24 '24 14:01 pvdbosch