OAS Validation error Parsing

I have a requirement where I have to send the customize the error response going back. currently i use  the below code.


<Set>
<Payload contentType="application/json" variablePrefix="@" variableSuffix="#">
{
"validationErrors": [
"@OASValidation.OAS-RequestValidate.fault.cause#"
]
}
</Payload>
</Set>

which gives output as 
{

    "validationErrors": [
        "OASValidation OAS-RequestValidate with resource "oas: //pet_V3.yaml": failed with reason: "[ERROR - Header parameter 'ID' is required on path '/Store/' but not found in request.: [], ERROR - Header parameter 'senderInfo' is required on path '/Store/' but not found in request.: []]""
    ]
}

But I want it to be output as 

{
    "validationErrors": [
"Header parameter Required": "ID" , 
"Header parameter Required": "senderInfo"
]    
}

How do I get just the field names that failed OAS validation

0 1 381
1 REPLY 1

Formatting the output error message isn't supported by the OAS validation policy but something you can achieve using Apigee's error handling functionality as described here https://cloud.google.com/apigee/docs/api-platform/fundamentals/fault-handling.

The easiest would probably be to define a regex pattern matching in a JS policy to extract the fields you're interested and then craft a new error message as the response body.

This might help you as an example of the implementation: https://github.com/apigee/devrel/tree/main/references/common-shared-flows/error-handling-v1/sharedfl...