Search code examples
raml

Define XML namespace in RAML Datatype


Is it possible to define an XML namespace in a RAML datatype? I found a reference to it being possible in the RAML spec on github, but I cannot get it working in MuleSofts API Designer.

For example I was thinking I could define my RAML as below, but I am getting an error in API Designer that the expected type is object, but it got a string.

#%RAML 1.0 DataType


type: object
properties: 
  top:
    type: object
    properties: 
      abc:
        xml:
          attribute: true
          name: abc 
      xmlNamespace:
        xml: 
          attribute: true
          namespace: http://google.com
      node:
        type: string
example:
  <xml>
    <top abc="123" xmlns="http://google.com">
      <node>12345</node>
    </top>
  </xml>

Solution

  • The namespace is for when the xml element should have a namespace like so:

    #%RAML 1.0 DataType
    properties: 
      top:
        type: object
        xml:
          name: top
          wrapped: true
          namespace: f
        properties: 
          abc:
            xml:
              attribute: true
              name: abc
    example:
      <mytype>
        <f:top abc="123">
        </f:top>
      </mytype>
    

    If you just want an attribute names xmlns then maybe try something like this:

    #%RAML 1.0 DataType
    properties: 
      top:
        type: object
        xml:
          name: top
          wrapped: true
        properties: 
          abc:
            xml:
              attribute: true
              name: abc
          xmlns:
            default: http://google.com
            xml:
              attribute: true
              name: xmlns
            
    example:
      <mytype>
        <top abc="123" xmlns="http://google.com">
        </top>
      </mytype>