belgif / rest-guide

REST Guidelines of Belgian government institutions
https://www.belgif.be/specification/rest/api-guide/
Apache License 2.0
26 stars 4 forks source link

Required properties should be explicitly defined #162

Closed pvdbosch closed 6 months ago

pvdbosch commented 11 months ago

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 commented 10 months ago

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