Search code examples
anypoint-studioraml

RAML Unknown facet 'types'


I am receiving an issue with a datatype .raml file that I am attempting to create. For some reason, it is stating that I am 'Specifying unknown facet 'types' as an error.

What is the proper way to go about defining an object in 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

Solution

  • You are currently using a so called RAML fragment which focuses on a single definition only. In your case a single type definition.

    You start defining multiple type definitions usually using types either in a root RAML file (indicated with #%RAML 1.0) or in a library (indicated with #%RAML 1.0 Library). So depending on what you try to achieve you either modify your data type fragment to only contain the definition of the Account type or you change #%RAML 1.0 DataType to #%RAML 1.0 Library so you can package multiple type definition into one; or you use both for max reusability.

    Let me show you how to use both:

    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
    

    In other type definition you could then use the library to reference to the account type. For example:

    bank.raml

    #%RAML 1.0 DataType
    
    uses:
      types: types.raml
    
    type: object
    properties:
      branch: string
      accounts:
        type: array
        items: types.Account
    

    Hope that helps you! Let me know if you have any further questions.