RAML文件中的命名空间

问题描述 投票:1回答:1

我在尝试创建RAML unsing库以定义XML类型时遇到一些问题。似乎正在向所有属性传播前缀。

该库是这样的:

#%RAML 1.0 Library

types:  
  book:
    type: object
    properties:
      id:
        type: integer
      title:
        type: string
      author: 
        type: string
    xml:
      prefix: 'smp'
      namespace: 'http://example.com/schema'
      name: 'book'

RAML是这个:

#%RAML 1.0

title: book test

uses:
  myLib: /libraries/types.raml

/book:
  description: book
  post:    
    body: 
      application/xml:
        type: myLib.book

这是为API发送的XML:

<?xml version="1.0" encoding="utf-8"?>
<smp:book xmlns:smp="http://example.com/schema">
    <id>0</id>
    <title>string</title>
    <author>string</author>
</smp:book>

我收到此错误:

{
    "code": "REQUEST_VALIDATION_ERROR",
    "message": "Invalid schema for content type application/xml. Errors: cvc-complex-type.2.4.b: The content of element 'smp:book' is not complete. One of '{\"http://example.com/schema\":id, \"http://example.com/schema\":title, \"http://example.com/schema\":author}' is expected.. "
}
api raml mulesoft
1个回答
0
投票

我想我知道这里发生了什么。在您的XML文档中,根标签“ book”位于名称空间“ http://example.com/schema”中。 'book'的子标签用命名空间not限定。我自己还没有尝试过,但是我suspect RAML会自动将'book'的命名空间传播到其属性上。但是,RAML规范确实允许在属性和类型上使用xml节点:XML Serialization of Type instances因此,您可以如下修改“ book”的定义:

#%RAML 1.0 Library

types:  
  book:
    type: object
    xml:
      prefix: 'smp'
      namespace: 'http://example.com/schema'
      name: 'book'
    properties:
      id:
        type: integer
        xml:
          namespace: ''
      title:
        type: string
        xml:
          namespace: ''
      author: 
        type: string
        xml:
          namespace: ''

如果不起作用,则可以用(手动创建的)文件'book.xsd'替换'book'类型的整个定义。确保xs:schema标记上的'elementFormDefault'属性设置为'unqualified'。然后从您的RAML中参考book.xsd。

© www.soinside.com 2019 - 2024. All rights reserved.