Skip to main content

invalid-additional-properties-usage

Prevents additionalProperties from being attached to a non-object schema.

AttributeValue
CategorySchema
MaturityPlatinum
OpenAPISwagger 2.0; OpenAPI 3.0, 3.1, 3.2
StarterOff
LenientWarning
RecommendedWarning
StrictWarning
CompleteError

Intent

additionalProperties controls unknown keys in an object. It has no useful meaning on scalar or array schemas, so leaving it there can hide a modeling mistake.

Flags

This rule reports a schema that:

  • declares additionalProperties; and
  • declares a type other than the text value object.

Does not flag

  • Object schemas using additionalProperties.
  • Schemas that omit additionalProperties.
  • Schemas with no type; other rules can require or validate type information.

See it fail

openapi: 3.0.3
info:
title: Customer API
version: 1.0.0
paths: {}
components:
schemas:
CustomerName:
type: string
additionalProperties: true

Specmatic reports that additionalProperties is ignored for type string and should be removed.

Fix it

Remove the object-only keyword:

CustomerName:
type: string

If the value should be a key-value object, correct its type:

CustomerLabels:
type: object
additionalProperties:
type: string

Configure

specmatic-linter.yaml
profiles:
default:
rules:
extends:
- recommended
override:
invalid-additional-properties-usage: error

Nearby rules

  • additional-properties-false
  • no-unconstrained-additional-properties
  • no-schema-type-mismatch