Skip to main content

string-schema-format-required

Requires unconstrained string properties and parameters to declare a format.

AttributeValue
CategorySchema
MaturityGold
OpenAPISwagger 2.0; OpenAPI 3.0, 3.1, 3.2
StarterOff
Lenient–StrictWarning
CompleteError

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 format nor a non-empty enum.
  • String schemas on query, path, header, or cookie parameters with neither format nor a non-empty enum.

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.