Order
This is a verification method that helps check whether the selected components are in the correct order according to their type and order scheme (ascending or descending). Only lists of non-complex values are accepted as input targets. To verify order of a list of objects, the object key (that needs to decide the order) must be selected as target.
Arguments
Name | Type | Description |
---|---|---|
Ascending | Boolean | Default: true . If false , the order scheme will be considered Descending . |
Examples
Verifying order of two types of tags
lists
Rule
Rule that verifies whether all tags
in an Operation Object are in alphabetical order and the global tags
are also defined alphabetically (w.r.t. to the name
key) can be defined as below:
{
"Id": "alphabetical-tags",
"Targets": [
{
"JsonPath": "$.paths.*.*.tags"//tags in an Operation Object
},
{
"JsonPath": "$.tags[*].name"//global or root-level tags
}
],
"VerificationMethod": "Order",
"Message": "Tags are not in an alphabetical order."
}
Input - Invalid
{
"openapi": "3.0.3",
"tags": [
{
"name": "playlist"
},
{
"name": "artist"
}
],
"paths": {
"/playlist": {
"get": {
"tags": [ "playlist", "private" ]
...........
}
},
"/artist": {
"post": {
"tags": [ "public", "artist" ]
...........
}
}
}
}
Input - Valid
{
"openapi": "3.0.3",
"tags": [
{
"name": "artist"
},
{
"name": "playlist"
}
],
"paths": {
"/playlist": {
"get": {
"tags": [ "playlist", "private" ]
...........
}
},
"/artist": {
"post": {
"tags": [ "artist", "public" ]
...........
}
}
}
}
Verifying order of schemas
keys
Rule
Rule that verifies whether all schema keys are in an alphabetical order or not can be defined as below:
{
"Id": "alphabetical-schema-keys",
"VerificationMethod": "Order",
"Targets": [
{
"JsonPath": "$.components.schemas",
"KeysOnly": true
}
],
"Message": "Schema keys are not in an alphabetical order."
}
Input - Invalid
{
"openapi": "3.0.3",
.........
"components": {
"schemas": {
"Dog": {
.........
},
"Cat": {
...........
}
}
}
}
Input - Valid
{
"openapi": "3.0.3",
.........
"components": {
"schemas": {
"Cat": {
...........
},
"Dog": {
.........
}
}
}
}