Skip to main content

schema-code-type-string

Requires an error schema's code property to use type: string.

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

Intent

String error codes remain stable when teams use names, prefixes, or numeric-looking values with leading zeros.

Flags

A code property in the first media-type schema of a 4xx or 5xx response when its type is not string. A missing type is also reported.

Does not flag

String codes, error schemas without code, and non-error responses. Use error-schema-code to require the property itself.

See it fail

responses:
'400':
description: Invalid request
content:
application/problem+json:
schema:
type: object
properties:
code:
type: integer

Diagnostic: Error property `code` should be string.

Fix it

responses:
'400':
description: Invalid request
content:
application/problem+json:
schema:
type: object
properties:
code:
type: string

Configure

profiles:
default:
rules:
extends: [recommended]
override:
schema-code-type-string: error

Nearby: error-schema-code, schema-message-type-string.