invalid-additional-properties-usage
Prevents additionalProperties from being attached to a non-object schema.
| Attribute | Value |
|---|---|
| Category | Schema |
| Maturity | Platinum |
| OpenAPI | Swagger 2.0; OpenAPI 3.0, 3.1, 3.2 |
| Starter | Off |
| Lenient | Warning |
| Recommended | Warning |
| Strict | Warning |
| Complete | Error |
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
typeother than the text valueobject.
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-falseno-unconstrained-additional-propertiesno-schema-type-mismatch