pattern-length-incompatible
Finds string schemas whose pattern cannot produce a value within the declared length range.
| Attribute | Value |
|---|---|
| Category | Schema |
| Maturity | Platinum |
| OpenAPI | Swagger 2.0; OpenAPI 3.0, 3.1, 3.2 |
| Starter | Off |
| Lenient | Warning |
| Recommended–Complete | Error |
Intent
A regex and length constraints should overlap. If they do not, every candidate value is invalid.
Flags
minLengthis greater than the longest string a supported pattern can match.maxLengthis smaller than the shortest string a supported pattern can match.
Specmatic evaluates fixed text, simple character classes, and {n}, {n,m}, or {n,} quantifiers. It skips patterns containing groups, alternation, *, +, ?, or escapes to avoid unreliable findings.
Does not flag
A compatible range, a schema without minLength or maxLength, or a complex pattern outside the supported analysis above.
See it fail
countryCode:
type: string
pattern: '^[A-Z]{2}$'
minLength: 3
The pattern produces exactly two characters, but the schema requires at least three.
Fix it
Align the length with the pattern:
countryCode:
type: string
pattern: '^[A-Z]{2}$'
minLength: 2
maxLength: 2
Configure
profiles:
default:
rules:
extends: [recommended]
override:
pattern-length-incompatible: warn
Nearby: invalid-min-length, invalid-max-length.