正确地创建一个RAML 1.0命名的例子。

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

我正在使用RAML 1.0来指定一个API,但在使用Named Example片段类型时遇到了问题。我看了许多教程和示例,但无法找到一个明确的指南,以了解该资源的预期。

我正在使用MuleSoft Anypoint Platform API Designer。(2020年5月)

这是我的DataType定义。

#%RAML 1.0 DataType
type: object
properties:
  display-name: 
    required: true
    type: string
  note-properties:
    required: true
    type: object
  note-data:
    required: true
    type: any

这是我的Named Example片段

#%RAML 1.0 NamedExample
noteExample:
    display-name: greeting
    note-properties: read-only
    note-data: Hello world

这里是引用这些的根文件。

#%RAML 1.0
title: sandbox API

types:
  noteType: !include definitions/noteType.raml

/note:
  get:
    responses:
      200:
        body:
          application/json:
            type: noteType
            examples: !include examples/noteExample.raml

问题是解析器(APIKit插件)将此报告为错误。 以下是来自设计中心的错误信息。

['note-properties']应该在 examplesnoteExample.raml (3, 1)处成为对象。

我也尝试了一个更简单的DataType定义,但我得到了同样的错误。

我的Named Example文件中是否有明显的错误。我知道一定有一个明确的规范,但到目前为止,我发现的是各种(偶尔是冲突的)例子。

rest mulesoft raml
1个回答
0
投票

...好吧,这很尴尬。错误信息确切地告诉了我们错误的地方。

它清楚地写着 "XXX应该是一个对象"

当我把 "命名示例 "改成这样时,:

#%RAML 1.0 NamedExample
  noteExample:
      display-name: greeting
      note-properties: 
        status: read-only
      note-data: Hello world

...其中的值为

笔记属性

是一个实际的对象,而不是一个简单的字符串(就像我的OP中那样),那么这样就可以了。

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