# schema-no-additional-properties

Source: https://api-genie.dev/docs/linter/openapi/rules/schema-no-additional-properties

A rule of the OpenAPI linter, which reads OpenAPI 3.0, 3.1 and 3.2 documents. 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](/docs/linter/openapi/rules/schema-no-contradictions) for the
`unevaluatedProperties` form that closes the combined schema instead.

## Examples

**Good**. The object is closed.

```yaml
components:
  schemas:
    User:
      type: object
      properties:
        firstName:
          type: string
        lastName:
          type: string
      additionalProperties: false
```

**Bad**. Any property is accepted.

```yaml
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.
