0
votes

I am using Anypoint Studio 7.2.3 and Mule runtime 4.1 to write my RAML.

I have a JSON schema for an order object and I also need a JSON schema for a list of order objects. I thought I could reference the order object in the JSON schema for the list of orders to save maintaining the same fields in 2 schemas but I am seeing an error because $schema appears twice and is showing the error when I add a JSON example of an order list in the RAML.

Is it possible to have a separate order object JSON schema that can be referenced by an order list JSON schema?

Order Object JSON Schema (cut down version)

{
    "type": "object",
    "$schema": "http://json-schema.org/draft-04/schema",
    "properties": {
        "orderId": {
            "type": "string",
            "maxLength": 255            
        },
        "comments": {
            "type": "string",
            "maxLength": 255            
        }                                       
    },
    "required": [
        "orderId"
    ]
}

Order List JSON Schema

{
    "type": "array",
    "$schema": "http://json-schema.org/draft-04/schema",
    "properties": {
        "$ref": "#Order"
    }
}

The below JSON schema works for order list but means I will need to maintain the fields in 2 separate schemas so any change to e.g. orderId will mean I will need to change it in both the order object schema and the order list schema.

{
    "type": "array",
    "$schema": "http://json-schema.org/draft-04/schema",
    "properties": {
        "orderId": {
            "type": "string",
            "maxLength": 255            
        },
        "comments": {
            "type": "string",
            "maxLength": 255            
        }                                       
    },
    "required": [
        "orderId"
    ]
}

Thanks for any help.

1
Take a look at json-schema.org/learn/… - References work in draft-4 too.Relequestual

1 Answers

0
votes

Just change "properties" to "items" in your OrderList schema. Also reference the name of the file in the same folder or insert the full path to a file located elsewhere. See the code below:

{
    "type": "array",
    "$schema": "http://json-schema.org/draft-04/schema",
    "items": {
        "$ref": "order.schema.json"
    }
}

[]'s