OpenAPI validation failed for nullable fields
search cancel

OpenAPI validation failed for nullable fields

book

Article ID: 250458

calendar_today

Updated On:

Products

CA API Gateway

Issue/Introduction

We are using the "Validate Against OpenAPI Document" assertion to check the content of incoming requests against a static YAML specification

A request field is marked as '"nullable": true' in the spec, but the validation assertion fails if the content is null

Environment

Release : 10.0

Component : API GATEWAY

Resolution

OpenAPI assertion uses json schema validator (v4) to validate the body. It seemed that nullable field is applicable to Open API 3.0 spec only. It is not part of JSON schema draft v4. We might need to find a way to translate this nullable field to JSON Schema v4.

The nullable field can be translated using anyOf. For now, this can be worked around by adjusting the schema like the example below:

EXISTING:

"comment": {  "pattern": "aa.*",  "type": "string",  "nullable": true}

 

NEW:

"comment": {  "anyOf": [    {      "pattern": "aa.*",      "type": "string"    },    {"type": "null"}  ]}


Also, another suggestion is to use the format like below:

EXISTING:

"comment": {  "pattern": "aa.*",  "type": "string",  "nullable": true}

NEW:

 "comment": {
                        "pattern": "aa.*",
                        "type":["string","null"]                 
                    }

Additional Information

This issue will be fixed in 10.0 CR06