Skip to main content

Pattern

This is a verification method that helps check whether the selected components are valid for provided Regex pattern or not. Only string values are accepted as input targets for this method.

Arguments

NameTypeDescription
RegexStringRequired. A valid regular expression that the target string component will be verified against. This must be a non-empty string.
ShouldMatchBooleanDefault: true. When false, the component is valid if it does not match the specified Regex pattern.

Examples

operationId Uses Camel Case Convention

Rule

Rule that verifies whether operationId in all Operation Objects across the document follow camel case conventions or not, can be defined as below:

{
"Id": "operation-id-camel-case",
"Targets": [
{
"JsonPath": "$.paths.*.*.operationId"
}
],
"VerificationMethod": "Pattern",
"VerificationMethodArgs": {
"Regex": "^[a-z]+(?:[A-Z][a-z]*)*$"
},
"Message": "Operation id does not follow camel case."
}

Input - Invalid

{
"openapi": "3.0.3",
.......
"paths": {
"/pets": {
"get": {
"operationId": "list-pets",
............
},
"post": {
"operationId": "create-pets",
..............
}
}
}
}

Input - Valid

{
"openapi": "3.0.3",
.......
"paths": {
"/pets": {
"get": {
"operationId": "listPets",
............
},
"post": {
"operationId": "createPets",
..............
}
}
}
}