The 'Ensure JSON Schema' assertion does not check for mandatory fields.

book

Article ID: 141880

calendar_today

Updated On:

Products

CLOUDTEST CA Application Test CA Cloud Test Mobile MOBILECLOUD Service Virtualization

Issue/Introduction

The 'Ensure JSON Schema' assertion is not throwing any error when mandatory fields are missing in the JSON request.
This assertion is failing only when request structure is incorrect. 

Environment

Release : 10.4, 10.5

Component : CA Service Virtualization

Resolution

Entries in the schema that are mandatory can be configured with the required keyword.
Here is an example schema configuration and a payload that fails:


schema:

{ "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "number" }
 },
  "required": ["name", "age"]
}


payload:

{  "name": "john"
}


Assertion result:
Assertion name: Ensure JSON Schema checks for: true is of type: Ensure JSON Schema.

Test Summary
  JSON schema validation failed. Found 1 issue.
    Issue: object has missing required properties (["age"])
      level: error
      schema: {"loadingURI":"#","pointer":""}
      instance: {"pointer":""}
      domain: validation
      keyword: required
      required: ["age","name"]
      missing: ["age"]

Additional Information

For more detail regarding JSON schema's, review: 
https://json-schema.org/understanding-json-schema/