Pattern conflicts with allowed string length

Issue ID: semantic-pattern-incompatible

Description

One or more strings in your API define a pattern that conflicts with the allowed length of the string. This could result in a null value for string.

For more details, see the OpenAPI Specification.

Example

The following is an example of how this type of risk could look in your API definition. The string defines a pattern but the maximum length allowed in the pattern is shorter than the required minLength of the same string:

{
    "parameters": {
        "in": "query",
        "name": "id",
        "type": "string",
        "description": "Identifier of the object to be extracted.",
        "pattern": "^[a-z]{10,20}$",
        "minLength": 25
    }
}

Or the pattern could require longer strings than maxLength allows:

{
    "parameters": {
        "in": "query",
        "name": "id",
        "type": "string",
        "description": "Identifier of the object to be extracted.",
        "pattern": "^[a-z]{10,20}$",
        "maxLength": 5
    }
}

Remediation

Make sure that the patterns you define for strings do not conflict with the minLength or maxLength properties.

{
    "parameters": {
        "in": "query",
        "name": "id",
        "type": "string",
        "description": "Identifier of the object to be extracted.",
        "pattern": "^[a-z]{25,40}$",
        "minLength": 25,
        "maxLength": 40
    }
}