Skip to main content

Required

This is a verification method that ensures the presence of specified properties within targeted OpenAPI components. Unlike OpenAPI's built-in required property, this method allows you to enforce the presence of any property, including vendor extensions.

Arguments

NameTypeDescription
PropertiesArray of StringsRequired. A list of property names that must be present in the target component. Each entry must be a valid, non-empty string.

Examples

Ensuring x-my-extension Exists in API Info

Rule

The following rule ensures that the x-my-extension property is always present inside the info object:

{
"Id": "require-x-my-extension",
"Targets": [
{
"JsonPath": "$.info"
}
],
"VerificationMethod": "Required",
"VerificationMethodArgs": {
"Properties": ["x-my-extension"]
},
"Message": "API info must contain the 'x-my-extension' property."
}

Input - Invalid

{
"openapi": "3.0.3",
"info": {
"title": "Petstore API",
"version": "1.0.0"
}
}

Input - Valid

{
"openapi": "3.0.3",
"info": {
"title": "Petstore API",
"version": "1.0.0",
"x-my-extension": "custom-metadata"
}
}

With this verification method, you can ensure critical properties exist within any OpenAPI component, enforcing better API consistency and governance.