Layer7 API Management

Expand all | Collapse all

How to define schema using Validate JSON Schema Assertion?

Jump to Best Answer
  • 1.  How to define schema using Validate JSON Schema Assertion?

    Posted 09-21-2015 02:30 AM

    Hi,

     

    Consider i have json like below,

     

    {

        "a": "b",

        "c": "d",

        "e": {

            "f": "g",

            "h": "1234"

        },

        "qwerty": [

            {

                "love": "kind"

            },

            {

                "love": "kind1"

            }

        ],

        "asdf": [

            {

                "omega": "12345",

                "omega1": "2345"

            },

            {

                "beta": "f9",

                "beta1": "f10"

            }

        ],

       "arrayval": ["1","2"]

    }

     

    1. I want to make "e" as optional, if input has "e" and then i want to make  "h":"1234" as optional ?

    2. Value "c" either can be integer/string ? how to provide this?

    3. How to define this "qwerty" array of object in JSON Schema Assertion? (NOTE: The Array will contain same schema for n times..)

    4. How to define this "asdf" array of object in JSON Schema Assertion? (NOTE: The Array will have different type of objects for n times..)

    5. How to define the key "arrayval" in JSON Schema Assertion?



  • 2.  Re: How to define schema using Validate JSON Schema Assertion?
    Best Answer

    Posted 09-21-2015 10:59 AM

    It is important to note that the API Gateway currently uses JSON Schema v2. This means that any element not explicitly set using the optional construct is considered required. We have a development incident (FR-814) for expanding this support but we are currently using JSON v2. To answer your specific questions:

     

    You can make the e object and h value optional using this construct: "optional": true. The applicable part of the JSON schema for this would be something as follows

    "e": {    "type": "object",

              "properties": { "f": { "type": "string" },

                    "h": {     "type": "integer",

                               "optional": true } } }

     

    You do not have to specify a value type for an object unless locking it down to a specific type. Not specifying the type attribute means that either strings or integers would be permitted.

     

    You can specify that an array is built from objects using the following:

    "qwerty": {     "type": "array",

                    "items": {

                         "type": "object" } }

     

    You can specify that an array is built of individual strings as follows:

    "qwerty": {     "type": "array",

                    "items": {

                         "type": "string" } }

     

    There are a large quantity of attributes that can be used in this regard--especially for arrays. You can specify a maximum or minimum number of items, enforce uniqueness. I would encourage you to look into the linked specification to see what other components meet your needs.



  • 3.  Re: How to define schema using Validate JSON Schema Assertion?

    Posted 09-21-2015 11:08 AM

    Thanks for the information. You are awesome!!!



  • 4.  Re: How to define schema using Validate JSON Schema Assertion?

    Posted 09-21-2015 11:15 AM

    Happy to be of assistance. Have a great day!



  • 5.  Re: How to define schema using Validate JSON Schema Assertion?

    Posted 01-21-2016 06:31 AM

    Hi goeer03,

     

    Any idea when JSON schema v4 will be supported into API Gateway ? Maybe it is already implemented in 9.0 gateway (I am currently working with 8.3/8.4 version).

     

    Thank you for your feedback



  • 6.  Re: How to define schema using Validate JSON Schema Assertion?

    Posted 01-25-2016 01:56 PM

    UP ?