在RAML数据类型中定义XML名称空间

时间:2018-10-09 03:01:39

标签: raml

是否可以在RAML数据类型中定义XML名称空间?我在RAML spec on github中找到了对它的引用,但是我无法在MuleSofts API Designer中使它起作用。

例如,我当时想我可以如下定义我的RAML,但是我在API Designer中收到一个错误,期望的类型是object,但是它有一个字符串。

#%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>

1 个答案:

答案 0 :(得分:0)

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>

如果您只想要一个名称为xmlns的属性,则可以尝试如下操作:

#%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>