string-schema-format-required
Requires unconstrained string properties and parameters to declare a format.
| Attribute | Value |
|---|---|
| Category | Schema |
| Maturity | Gold |
| OpenAPI | Swagger 2.0; OpenAPI 3.0, 3.1, 3.2 |
| Starter | Off |
| Lenient–Strict | Warning |
| Complete | Error |
Intent
A format gives generic strings useful domain meaning, improving generated examples, validation, and client types.
Flags
- Direct string properties of component schemas with neither
formatnor a non-emptyenum. - String schemas on query, path, header, or cookie parameters with neither
formatnor a non-emptyenum.
Nested component properties and body-only inline strings are not checked.
See it fail
components:
schemas:
Customer:
type: object
properties:
email:
type: string
Diagnostic: String properties should define a format.
Fix it
email:
type: string
format: email
An enum also satisfies the rule:
status:
type: string
enum: [active, inactive]
Configure
profiles:
default:
rules:
extends: [recommended]
override:
string-schema-format-required: error
Nearby: string-parameter-pattern-required, string-max-length-or-enum.