Skip to main content

string-max-length-or-enum

Requires every resolved string schema to define maxLength, enum, or const.

AttributeValue
CategorySchema
MaturityPlatinum
OpenAPISwagger 2.0; OpenAPI 3.0, 3.1, 3.2
StarterOff
LenientWarning
Recommended–CompleteError

Intent​

Bounded strings limit payload growth. Finite enum and const values provide an equivalent bound without maxLength.

Flags​

Schemas whose resolved type includes string and which omit all three fields: maxLength, enum, and const.

The rule checks field presence; another rule validates whether a supplied bound or enum is internally valid.

See it fail​

displayName:
type: string

Diagnostic: String schemas should define \maxLength`, `enum`, or `const`.`

Fix it​

displayName:
type: string
maxLength: 100

Or use a finite set:

status:
type: string
enum: [active, inactive]

Configure​

profiles:
default:
rules:
extends: [recommended]
override:
string-max-length-or-enum: warn

Nearby: length-exceeds-limit, invalid-max-length.