Skip to main content
In this scenario, the application of the JSON Schema Validation policy to a Mock API created on Apinizer will be tested. Assuming that the JSON body of incoming requests in the scenario is the same, let’s add this to the All section. Adding JSON Schema Validation policy to All section We add JSON Schema Validation as a policy. Adding JSON Schema Validation policy Example request body in Mock Api will be as follows:
{
  "Sorgula": {
    "kriterListesi": {
      "BilesikKutukSorgulaKimlikNoSorguKriteri": {
        "DogumAy": 5,
        "DogumGun": 21,
        "DogumYil": 1990,
        "KimlikNo": "12345678901"
      }
    }
  }
}
A JSON Schema Validation suitable for this includes the following:
  • DogumAy: A value between 1 and 12 can be sent.
  • DogumGun: A value between 1 and 31 can be sent.
  • DogumYil: A value between 1800 and 2100 can be sent.
  • KimlikNo: Must be a string (Identity number) with a length of 11 characters.
JSON Schema Validation to be added to the policy:
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "Sorgula": {
      "type": "object",
      "properties": {
        "kriterListesi": {
          "type": "object",
          "properties": {
            "BilesikKutukSorgulaKimlikNoSorguKriteri": {
              "type": "object",
              "properties": {
                "DogumAy": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 12
                },
                "DogumGun": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 31
                },
                "DogumYil": {
                  "type": "integer",
                  "minimum": 1800,
                  "maximum": 2100
                },
                "KimlikNo": {
                  "type": "string",
                  "minLength": 11,
                  "maxLength": 11
                }
              },
              "required": ["DogumAy", "DogumGun", "DogumYil", "KimlikNo"]
            }
          },
          "required": ["BilesikKutukSorgulaKimlikNoSorguKriteri"]
        }
      },
      "required": ["kriterListesi"]
    }
  },
  "required": ["Sorgula"]
}
The JSON Schema Validation content above is added to the “Schema” field in the image below and saved. JSON Schema Validation Schema field When we send a request from the test console, KimlikNo was entered as 12 characters and validation was performed. We received a warning that it can only be 11 characters long. JSON Schema Validation test result