我收到的是我正在尝试创建的数据类型.raml文件的问题。出于某种原因,它声称我'指定未知方面'类型'为错误。
在RAML中定义对象的正确方法是什么?
#%RAML 1.0 DataType
types:
Account:
type: object
displayName: Account
description: Salesforce Account Object
properties:
id:
type: string
description: Id of the Salesforce Account
ns_id:
type: string
description: Id of NetSuite Customer
name:
type: string
description: Name of Salesforce Account
phone:
type: string
description: Phone Number of Salesforce Account
website:
type: string
description: Website of the Salesforce Account
owner:
type: string # This probably needs to be of type Owner
description: Owner of Account
active_cmrr:
type: number
description: Active CMRR of Account
billing_address:
type: string
description: Billing Address of Account
subscription_start_date:
type: date-only
description: Salesforce Account Subscription Start Date
subscription_end_date:
type: date-only
description: Salesforce Account Subscription End Date
#Sometype of Opportunity list
#opportunities:
# type: Opportunity[]
# description: List of Account Opportunities
答案 0 :(得分:4)
您目前正在使用所谓的RAML片段,该片段仅关注单个定义。在您的情况下是单一类型定义。
您通常在根RAML文件(用types
表示)或库(用#%RAML 1.0
表示)中使用#%RAML 1.0 Library
定义多个类型定义。因此,根据您尝试实现的目标,您可以修改数据类型片段以仅包含Account
类型的定义,或者将#%RAML 1.0 DataType
更改为#%RAML 1.0 Library
,以便将多个类型定义打包到一;或者你同时使用它们以获得最大的可重用性。
让我告诉你如何使用两者:
<强> account.raml 强>
#%RAML 1.0 DataType
type: object
displayName: Account
description: Salesforce Account Object
properties:
id:
type: string
description: Id of the Salesforce Account
ns_id:
type: string
description: Id of NetSuite Customer
name:
type: string
description: Name of Salesforce Account
phone:
type: string
description: Phone Number of Salesforce Account
website:
type: string
description: Website of the Salesforce Account
owner:
type: string # This probably needs to be of type Owner
description: Owner of Account
active_cmrr:
type: number
description: Active CMRR of Account
billing_address:
type: string
description: Billing Address of Account
subscription_start_date:
type: date-only
description: Salesforce Account Subscription Start Date
subscription_end_date:
type: date-only
description: Salesforce Account Subscription End Date
#Sometype of Opportunity list
#opportunities:
# type: Opportunity[]
# description: List of Account Opportunities
<强> types.raml 强>
#%RAML 1.0 Library
types:
Account: !include account.raml
在其他类型定义中,您可以使用库来引用帐户类型。例如:
<强> bank.raml 强>
#%RAML 1.0 DataType
uses:
types: types.raml
type: object
properties:
branch: string
accounts:
type: array
items: types.Account
希望对你有所帮助!如果您有任何其他问题,请与我们联系。