Avoid using keywords in JSON schema definition

Avoid using keywords in JSON schema definition

book

Article ID: KB0079173

calendar_today

Updated On:

Products Versions
TIBCO ActiveMatrix BusinessWorks 6.x

Description

Using keyword like Array in the JSON definition causes the "Example Value" in the swagger UI to skip the element name as part of response schema.

JSON schema definition : 

  "definitions" : {
    "stockArray" : {
      "type" : "object",
      "properties" : {
        "stock" : {
          "type" : "array",
          "items" : {
            "$ref" : "#/definitions/stock",
            "uniqueItems" : false
          }
        }
      }
    },
    "stock" : {
      "type" : "object",
      "required" : [ "ProductID" ],
      "properties" : {
        "ProductID" : {
          "type" : "string"
        },
        "AvailableStock" : {
          "type" : "integer"
        },
        "Discontinued" : {
          "type" : "boolean"
        }
      }
    }
  }

If the keyword "Array" is used, the output is like below : 

[
  {
    "ProductID": "string",
    "AvailableStock": 0,
    "Discontinued": true
  }
]

If the keyword "Array" is renamed to something like Array1,(renamed stockArray to stockArray1) the output is like below : 

{
  "stock": [
    {
      "Discontinued": true,
      "ProductID": "string",
      "AvailableStock": 0
    }
  ]
}

 

Issue/Introduction

Using keyword like Array in the JSON definition it causes the "Example Value" in the swagger UI to skip the element name as part of response schema.

Resolution

Array is Keyword in swagger and cannot be used for elements as suffix. This is documented here :

https://docs.tibco.com/pub/activematrix_businessworks/6.5.0/doc/html/GUID-06687C9D-F928-4F14-B23F-2067266CE35A.html