数组JSON模式中实体的参考对象JSON模式

问题描述 投票:0回答:1

我正在使用Anypoint Studio 7.2.3和Mule运行时4.1编写我的RAML。

我有一个用于订单对象的JSON模式,并且我还需要一个用于订单对象列表的JSON模式。我以为可以在JSON架构中引用订单对象以保存两个架构中相同字段的订单列表,但是我看到一个错误,因为$ schema出现了两次,并且在添加一个JSON示例时显示了错误RAML中的订单列表。

是否可以有一个可由订单列表JSON模式引用的单独的订单对象JSON模式?

订购对象JSON架构(简化版)

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

订单列表JSON模式

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

下面的JSON模式适用于订单列表,但意味着我将需要在2个独立的模式中维护字段,因此,例如orderId表示我将需要在订单对象架构和订单列表架构中对其进行更改。

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

感谢您的帮助。

mule jsonschema anypoint-studio raml
1个回答
0
投票

只需在您的OrderList模式中将“属性”更改为“项目”。另外,请在同一文件夹中引用文件名,或在其他位置插入文件的完整路径。参见下面的代码:

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

[]的

© www.soinside.com 2019 - 2024. All rights reserved.