Length
This is a verification method that helps check whether the selected components follow length restrictions or not. Based on the type of selected component the following verification is done:
- For a string value, length of the string is verified.
- For a numeric value, the value itself is verified.
- For a list, the count of items in the list is verified.
- For an object, the count of properties in the object is verified.
Arguments
Name | Type | Description |
---|---|---|
Maximum | Number | The maximum allowed limit for a value. The value must not be greater than this limit. It may be equal to the limit if ExclusiveMaximum is set to false . |
ExclusiveMaximum | Boolean | Default: false . If true , the input value should not be equal to the limit set in Maximum . |
Minimum | Number | Default: 0 . The minimum allowed limit for a value. The value must not be less than this limit. It may be equal to the limit if ExclusiveMinimum is set to false . |
ExclusiveMinimum | Boolean | Default: false . If true , the input value should not be equal to the limit set in Minimum . |
Examples
Verifying length of operationId
Rule
Rule that verifies whether all operationId
in an OpenAPI document are equal to/under 30 characters in length, can be defined as below:
{
"Id": "operation-id-max-length",
"Targets": [
{
"JsonPath": "$.paths.*.*.operationId"
}
],
"VerificationMethod": "Length",
"VerificationMethodArgs": {
"Maximum": 30
},
"Message": "Operation id is greater than 30 characters."
}
Input - Invalid
{
"openapi": "3.0.3",
.......
"paths": {
"/pets": {
"get": {
"operationId": "this-operation-id-crosses-the-30-mark",
............
},
"post": {
"operationId": "this-operation-id-also-crosses-the-30-mark",
..............
}
}
}
}
Input - Valid
{
"openapi": "3.0.3",
.......
"paths": {
"/pets": {
"get": {
"operationId": "this-is-a-valid-operation-id",
............
},
"post": {
"operationId": "this-is-okay-too",
..............
}
}
}
}
Verifying length of tags
lists
Rule
Rule that verifies whether all tags
lists in Operation Objects contain at least one tag.
{
"Id": "atleast-one-tag",
"Targets": [
{
"JsonPath": "$.paths.*.*.tags"
}
],
"VerificationMethod": "Length",
"VerificationMethodArgs": {
"Minimum": 1
},
"Message": "Operation has no tags."
}
Input - Invalid
{
"openapi": "3.0.3",
.......
"paths": {
"/pets": {
"get": {
"tags": []
............
}
}
}
}
Input - Valid
{
"openapi": "3.0.3",
.......
"paths": {
"/pets": {
"get": {
"tags": [ "pets" ]
............
}
}
}
}
Verifying total schemas
Rule
Rule that verifies whether the components.schemas
object contains at least one schema definition but does not contain more than 200 definitions.
{
"Id": "some-schemas",
"Targets": [
{
"JsonPath": "$.components.schemas"
}
],
"VerificationMethod": "Length",
"VerificationMethodArgs": {
"Minimum": 1,
"Maximum": 200
}
}
Input - Invalid
{
"openapi": "3.0.3",
.......
"components": {
"schemas": {}
}
}
Input - Valid
{
"openapi": "3.0.3",
.......
"components": {
"schemas": {
"Pet": {
............
}
}
}
}