RAML 未知方面 'types'

RAML Unknown facet 'types'

我在尝试创建数据类型 .raml 文件时遇到问题。出于某种原因,它表明我 'Specifying unknown facet 'types' 作为错误。

在 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

您当前使用的是所谓的 RAML 片段,它只关注单个定义。在您的情况下,单个类型定义。

您通常在根 RAML 文件(用 #%RAML 1.0 表示)或库(用 #%RAML 1.0 Library 表示)中使用 types 开始定义多个类型定义。因此,根据您尝试实现的目标,您要么修改数据类型片段以仅包含 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

希望对您有所帮助!如果您还有其他问题,请告诉我。