Custom Functions don't return all messages generated

Hi,
I have a json path like that ‘$.paths.[post,put,patch,get].parameters.[?(@.schema && @.in == ‘body’)]’ it return all my requests payload that I want check if some required attributes was added. I created a custom function that read all properties within of the schema of each request payload. Like that.

module.exports = (targetVal) => {
    let errorsMessageArray = [];
    //call the function to process all request schema definition
    processRequestDefinition(targetVal.schema.properties, errorsMessageArray);
    return errorsMessageArray;
};

The array json has four items, it means we have four payload requests to be processed. it is after filter with json path showed above.

The function ‘processRequestDefinition’ add all errors found, I checked that through logs. There are several errors added in ‘errorsMessageArray’ for each item processed, four in our case here.

However, when the errors are shown only four errors are showed, one for each item processed, and the Spectral got only one item(error message) per loop and show.

Do you know of any way to show all errors added to the collection variable ‘errorsMessageArray’?

function processRequestDefinition(targetVal, errorsMessageArray) {

    try {

        for (let property in targetVal) {

            if (targetVal[property].type === "string" && targetVal[property].format !== 'date' && targetVal[property].format != 'date-time' && targetVal[property].enum === undefined) {

                if (targetVal[property].description === undefined) {

                    errorsMessageArray.push(

                        {

                            message: `The ${property} parameter must have the "description" field.`

                        }

                    )

                }

                if (targetVal[property].example === undefined) {

                    errorsMessageArray.push(

                        {

                            message: `The ${property} parameter must have the "example" field.`

                        }

                    )

                }

                if (targetVal[property].minLength === undefined) {

                    errorsMessageArray.push(

                        {

                            message: `The ${property} parameter must have the "minLength" field.`

                        }

                    )

                }

                if (targetVal[property].maxLength === undefined) {

                    errorsMessageArray.push(

                        {

                            message: `The ${property} parameter must have the "maxLength" field.`

                        }

                    )

                }

                if (targetVal[property].pattern === undefined) {

                    errorsMessageArray.push(

                        {

                            message: `The ${property} parameter must have the "pattern" field.`

                        }

                    )

                }

            } else if (targetVal[property].type === "string" && targetVal[property].format === 'date') {

                if (targetVal[property].description === undefined) {

                    errorsMessageArray.push(

                        {

                            message: `The ${property} parameter must have the "description" field.`

                        }

                    )

                }

                if (targetVal[property].example === undefined) {
                    errorsMessageArray.push(
                        {
                            message: `The ${property} parameter must have the "example" field.`
                        }
                    )
                }
                if (targetVal[property].pattern === undefined) {
                    errorsMessageArray.push(
                        {
                            message: `The ${property} parameter must have the "pattern" field.`
                        }
                    )
                }
            } else if ((targetVal[property].type === "integer" || targetVal[property].type === "number")) {
                if (targetVal[property].description === undefined) {
                    errorsMessageArray.push(
                        {
                            message: `The ${property} parameter must have the "description" field.`
                        }
                    )
                }
                if (targetVal[property].example === undefined) {
                    errorsMessageArray.push(
                        {
                            message: `The ${property} parameter must have the "example" field.`
                        }
                    )
                }
                if (targetVal[property].minimum === undefined) {
                    errorsMessageArray.push(                {
                            message: `The ${property} parameter must have the "minimum" field.`
                        }
                    )
                }
                if (targetVal[property].maximum === undefined) {
                    errorsMessageArray.push(              {
                            message: `The ${property} parameter must have the "maximum" field.`
                        }
                    )
                }
                if (targetVal[property].pattern === undefined) {
                    errorsMessageArray.push(
                        {
                            message: `The ${property} parameter must have the "pattern" field.`
                        }
                    )
                }
            } else if (targetVal[property].type === "object") {
                //if the property is an object call again the function
                processRequestDefinition(targetVal[property].properties, errorsMessageArray, rootPath)
            } else if (targetVal[property].type === "array") {
                //if the property is an array call again the function
                processRequestDefinition(targetVal[property].items.properties, errorsMessageArray, rootPath)
            }
        }
    } catch (error) {
        console.error('Error in processRequestDefinition: ' + error)
    }
}