RAML 文件中的命名空间 [英] Namespace in RAML file

查看:34
本文介绍了RAML 文件中的命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试创建 RAML unsing 库来定义 XML 类型时遇到了一些问题.看起来是将前缀传播到所有属性.

I'm facing some problems trying to create a RAML unsing Library to define the types for a XML. Looks like is propagating the prefix to all the atributes.

图书馆是这样的:

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

This is the XML that is send for the API:

<?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.. "
}

推荐答案

添加另一个答案,以清理凌乱的线程并允许对话继续而不会造成混乱...

Adding another answer, to clean up the messy thread and allow the conversation to continue without causing confusion...

你的 xsd 有两个绝对巨大的错误.

Your xsd has two absolutely huge faults.

  • 您尚未声明全局元素book".错误消息非常清楚,所以您错过了.
  • 您尚未为此 XSD 中的全局元素声明目标命名空间

我在下面更改了您的 XSD,它比您发布的更有效.请试一试.

I have changed your XSD below, and it is much more likely to work than the one that you posted. Please give it a try.

<schema 
    attributeFormDefault="unqualified" 
    elementFormDefault="unqualified" 
    xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://example.com/schema"
>

  <element name="book">
    <complexType>
      <sequence>
        <element name="id" type="byte"/>
        <element name="title" type="string"/>
        <element name="author" type="string"/>
      </sequence>
    </complexType>
  </element>
</schema>

这篇关于RAML 文件中的命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆