Validation for optional params in response with null values fails

Issue #156 invalid
Yulia Glazunova created an issue

Hi. I'm wondering what was changed between old (swagger2.0) and new (openApi3.0) schema validation rule for optional parameters in response object? I switched to latest swagger request validator and some of my tests started to fail with messages like that:

Instance type (null) does not match any allowed primitive type (allowed: [\"...\"])"

this basically comes from json validator, but whitelist rules should actually "whitelist" these errors since they appear for optional fields in responce. This was working fine with swagger 2.0 schema and latest v1 validator (v1.5.0). Here is sample schema of Response object I have:

  Asset:
      type: object
      required:
        - fileName
        - id       
      properties:
        id:
          type: integer
          format: int64
        fileName:
          type: string
        fileTitle:
          type: string

Here is sample response from service

{
    "id": 109,  
    "fileName": "test.mp4",
    "fileTitle": null
}

validation message I get:

"[Path '/fileTitle'] Instance type (null) does not match any allowed primitive type (allowed: [\"string\"])"

If you could point me some specific class in the code, I can try to implement the fix and create PR for that. Really appreciate any kind of help.

Comments (3)

  1. Yulia Glazunova reporter

    After some extra research I found schema 3.0 allows nullable option for properties which solves my issue.

  2. Log in to comment