schema-no-additional-properties
Since 0.0.1 · fixed by --fix · In the rulesets: Recommended at error, Strict at error, All at error
This rule checks that every object schema has additionalProperties: false.
Rule details
JSON Schema accepts properties a schema does not declare unless the schema says otherwise. An
open object hides a misspelled property name in a request (emial is accepted and ignored),
lets a client send fields the server stores without validating, and leaves generated code to
guess whether a map is needed.
The rule reports Object schema does not disable additional properties on each schema whose
type includes object and which does not set additionalProperties: false. Where a schema is
extended with allOf, closing the base schema makes every extension invalid; see
schema-no-contradictions for the
unevaluatedProperties form that closes the combined schema instead.
Examples
Good. The object is closed.
components:
schemas:
User:
type: object
properties:
firstName:
type: string
lastName:
type: string
additionalProperties: false
Bad. Any property is accepted.
components:
schemas:
User:
type: object
properties:
firstName:
type: string
lastName:
type: string
Automatic fixes
--fix adds additionalProperties: false to each object schema that lacks it.
Turn it off or change its severity
In apigenie.yaml, off turns the rule off and warning or error sets its severity; a rule with options takes the severity and the options as a pair, [warning, options]. lint.rules has the details.
commands:
lint:
rules:
schema-no-additional-properties: off